Cannot bind to KeyValueConfigurationCollection

3 posts, 0 answers
  1. Ricky
    Ricky avatar
    247 posts
    Member since:
    Jun 2007

    Posted 15 Oct 2007 Link to this post

    Hi, I try to bind a gridview to an instance of KeyValueConfigurationCollection as follows:

    private void WebHRSnifferForm_Load(object sender, EventArgs e)
            {
                dataBind104ComSettingGrid();

            }
            private void dataBind104ComSettingGrid()
            {
                // QueryStringParams is type of KeyValueConfigurationCollection
                Grid104CompSetting.DataSource = webHRConfig.OneZeroFour.Company.QueryStringParams.GetEnumerator();
            }

    But it seems the girdview cannot locate the properties exposed by KeyValueConfigurationElement that is contained within KeyValueConfigurationCollection. So no columns are created.

    Is there anything I should implement to let gridview bind to KeyValueConfigurationCollection.

    Thanks a lot.
    Ricky.

  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 16 Oct 2007 Link to this post

    Hello Ricky,

    Thank you for writing.

    The RadGridView currently does not support Hashtable types of collections like the KeyValueConfigurationCollection.

    You can use this workaround for the time being:

    private BindingList<KeyValueElement> confList; 
    private KeyValueConfigurationCollection config; 
     
    private void Form3_Load(object sender, EventArgs e) 
        config = new KeyValueConfigurationCollection(); 
        config.Add("TestKey1""TestValue1"); 
        config.Add("TestKey2""TestValue2"); 
        config.Add("TestKey3""TestValue3"); 
        config.Add("TestKey4""TestValue4"); 
        config.Add("TestKey5""TestValue5"); 
        config.Add("TestKey6""TestValue6"); 
        config.Add("TestKey7""TestValue7"); 
     
        confList = new BindingList<KeyValueElement>(); 
        foreach(KeyValueConfigurationElement elem in config) 
        { 
            confList.Add(new KeyValueElement(elem.Key, elem.Value)); 
        } 
     
        radGridView1.DataSource = confList; 
     
        //make changes to collection............ 
        config.Clear(); 
        foreach(KeyValueElement elem in confList) 
        { 
            config.Add(new KeyValueConfigurationElement(elem.Key,elem.Value)); 
        } 
     
    public class KeyValueElement 
        private string key; 
        private string val; 
     
        public KeyValueElement() 
        { 
            this.key = ""
            this.val = ""
        } 
     
        public KeyValueElement(string key, string value) 
        { 
            this.key = key; 
            this.val = value; 
        } 
     
        public string Value 
        { 
          get { return val; } 
          set { val = value; } 
        } 
     
        public string Key 
        { 
            get { return key; } 
            set { key = value; } 
        } 

    I hope this helps. Please contact us again if we could be of any additional service.

    All the best,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ricky
    Ricky avatar
    247 posts
    Member since:
    Jun 2007

    Posted 16 Oct 2007 Link to this post

    Thanks a lot.
    Ricky.
Back to Top