Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DictionaryEntry de = (DictionaryEntry)listbox.SelectedItem;
- string htKey = de.Key.ToString();
- public Form1()
- {
- InitializeComponent();
- this.listBox1.DisplayMember = "Name";
- this.listBox1.ValueMember = "ID";
- this.listBox1.Items.Add(new Test(1, "A"));
- this.listBox1.Items.Add(new Test(2, "B"));
- this.listBox1.Items.Add(new Test(3, "C"));
- this.listBox1.Items.Add(new Test(4, "D"));
- this.listBox1.Items.Add(new Test(5, "E"));
- }
- private void OnSelectedIndexChanged(object sender, EventArgs e)
- {
- if(-1 != this.listBox1.SelectedIndex)
- {
- Test t = this.listBox1.Items[this.listBox1.SelectedIndex] as Test;
- if(null != t)
- {
- this.textBox1.Text = t.Name;
- }
- }
- }
- private void ListBox1_SelectedValueChanged(object sender, EventArgs e)
- {
- if (ListBox1.SelectedIndex != -1)
- {
- string orbit = ListBox1.SelectedValue.ToString();
- }
- }
- ArrayList planets = new ArrayList();
- planets.Add(new Planet("Mercury", "1"));
- planets.Add(new Planet("Venus", "2"));
- //Remember to set the Datasource
- ListBox1.DataSource = planets;
- //Name and Orbit are properties of the 'Planet' class
- ListBox1.DisplayMember = "Name";
- ListBox1.ValueMember = "Orbit";
- KeyValuePair<int, string> kvp = (KeyValuePair<int, string>)listBoxSystems.SelectedItem;
- string szValue = kvp.Value;
- ListBox1.Items[1].toString();//Get value of the #1 Item in the ListBox;
- String Value;
- for(int c=0;c<ListBox1.Items.Count;c++){
- Value = Value + ListBox1.Items[c].toString();
- }
- //Thats it
Add Comment
Please, Sign In to add comment