1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How can I make my custom IndexCataloguePicker?

How can I make my custom IndexCataloguePicker?

7 posts, 1 answered
  1. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    12 Jul 2010
    Link to this post
    I've setup everything, but I want to return a string[] which is supposed to be the array of names of the index catalogues.

    The problem is that it appears as String[] Array instead of "Site,News,Others"...

    What should I do to have all the strings instead of the String[] Array ?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Jul 2010
    Link to this post
    Hello Bruno Michels,

    You need to get a pair.Key of IndexingManager.IndexingServices dictionary.


    IDictionary<string, IIndexingService> collection = IndexingManager.IndexingServices;
         foreach (KeyValuePair<string, IIndexingService> pair in collection)
         {
             var indexName = pair.Key;
         }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    13 Jul 2010
    Link to this post
    I do that.
    I've modified the Value with the name

    this.ViewState["IndexCatalogues"];

    When returning it looks like

    string[] { "Site", "Other" }

    But it doesn't show as "Site,Other"

    Here is my code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using QUAY.Web.UI;
    using QUAY.Web.UI.Admin.WebEditor;
    using QUAY.Web.UI.Extenders;
    using Telerik.Cms.Web.UI;
    using Telerik.Search.Engine;
     
    namespace QUAY.Sitefinity.Search.Admin.WebEditor
    {
        public class IndexSelector : CustomControl, IWebEditorSelector<string[]>, IWebUITypeEditor
        {
            private Repeater indexCatalogueList;
            private CheckBox indexCatalogue;
     
            public override void Initialize()
            {
                this.InitDefaultValues();
     
                var _this = this;
     
                indexCatalogueList.DataSource = IndexingManager.IndexingServices;
                indexCatalogueList.ItemDataBound += (sender, e) =>
                {
                    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                    {
                        var indexCatalogueField = e.Item.FindControl<CheckBox>("indexCatalogue");
     
                        indexCatalogueField.CheckedChanged += (cSender, cE) =>
                        {
                            if (_this.Value == null) _this.Value = new string[] { indexCatalogueField.Text };
                            else
                                _this.Value = _this.Value.Union(new string[] { indexCatalogueField.Text }).ToArray();
                        };
     
                        var kv = (KeyValuePair<string, IIndexingService>)e.Item.DataItem;
                        var indexingService = kv.Value;
                        indexCatalogueField.Text = " " + indexingService.Name;
                    }
                };
                indexCatalogueList.DataBind();
            }
     
            public string[] Value
            {
                get
                {
                    return (string[])this.ViewState["IndexCatalogues"];
                }
                set
                {
                    this.ViewState["IndexCatalogues"] = value;
                }
            }
     
            #region IWebUITypeEditor Members
     
            public bool AutoSelect { get; set; }
     
            public void EditValue(object value)
            {
                this.Value = (string[])value;
            }
     
            public System.Drawing.Design.UITypeEditorEditStyle GetEditStyle()
            {
                return default(System.Drawing.Design.UITypeEditorEditStyle);
            }
     
            public Control HostControl { get; set; }
     
            public string Title { get; set; }
     
            public object TypeContainer { get; set; }
     
            object IWebUITypeEditor.Value
            {
                get
                {
                    return this.Value as object;
                }
                set
                {
                    this.Value = (string[])value;
                }
            }
     
            public event EventHandler<ValueChangedEventArgs> ValueChanged;
     
            #endregion
        }
    }

    CustomControl is the same as your simple control, it just loads an ASCX.

    IWebEditorSelector<T> is the following interface

    namespace QUAY.Web.UI.Admin.WebEditor
    {
        public interface IWebEditorSelector<T>
        {
            T Value { get; set; }
        }
    }


    I did a content selector with it before and it works just fine, the content selector returns a Guid instead of a string[].

    That's my problem, I don't know how can I make the string[] appear as a String.Join(",", x) on the textbox field...
  4. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    13 Jul 2010
    Link to this post
    And it seems the values are not being saved...

    On the admin I can even see the correct value on the control (when I edit and select some value), but even saving the page afterward it doesn't save this value on the database...

    What am I doing wrong?

    I just want to get a string[] where each position contains the name of a search index.
    Can you provide a example how to achieve that? (nevermind my code)
  5. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    13 Jul 2010
    Link to this post
    I believe I'm missing a TypeConverter.

    Is there any for string[] ? If there isn't, how can I implement one ?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Jul 2010
    Link to this post
    Hi Bruno Michels,

    There is Telerik.Framework.Utilities.StringArrayConverter - implements methods that convert string representation of semicolon delimited strings to string array and vice versa. In NET Framework Class Library here is a public class StringArrayConverter that you can use. You could also take a look at Using Non-string Properties with Controls



    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  7. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    13 Jul 2010
    Link to this post
    Problem solved.


    [TypeConverter("Telerik.Framework.Utilities.StringArrayConverter, Telerik.Framework")]
Register for webinar
7 posts, 1 answered