This is a migrated thread and some comments may be shown as answers.

Cannot bind to KeyValueConfigurationCollection

2 Answers 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ricky
Top achievements
Rank 1
Ricky asked on 16 Oct 2007, 04:04 AM
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 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 16 Oct 2007, 10:55 AM
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
0
Ricky
Top achievements
Rank 1
answered on 16 Oct 2007, 02:27 PM
Thanks a lot.
Ricky.
Tags
GridView
Asked by
Ricky
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Ricky
Top achievements
Rank 1
Share this question
or