Share via


Accessing Dictionary object collection in a listbox

Question

Thursday, September 10, 2009 11:49 AM

Hi,

I have 10 buttons, 

Dictionary<string, ButtonStateCollection> parameter = new Dictionary<string,ButtonStateCollection>();

parameter = obj.GetAllButtonState();

In this parameter am getting all the 10 buttons state[string(Button Name)& True/False[enabled/Disabled]]

Now i need all this information,the keys and values in a listbox

How to do that?

Help me

Regards, Antony Software Engineer

All replies (1)

Thursday, September 10, 2009 1:14 PM âś…Answered

Bind the dictionary to the ListBox.

Dictionary<String, ButtonStateCollection> parameter = new Dictionary<String, ButtonStateCollection>();

......Add items to dictionary..........

listBox1.DataSource = new BindingSource(parameter , null);
listBox1.DisplayMember = "Key";
listBox1.ValueMember = "Value";
listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
     ButtonStateCollection bsc = listBox1.SelectedValue as ButtonStateCollection;
}John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com