task -creating dropdownlist boxs and accessing them in c#
-
jueves, 03 de mayo de 2012 12:29
create two dropdown listbox called "names" and "id" .the names dropdownlist consist of names like jony,zen,mortin and id drop downlist consist of id 1,4,5 ....task is when one select a name from name dropdownlist the corresponding id for that name should be visible in id dropdownlist..pls provide code in c#
sel.........
Todas las respuestas
-
jueves, 03 de mayo de 2012 14:53
Hi,
Is names and corresponding Id's are in single entity?
class Item { public int Id { get; set; } public string Name { get; set; } }
You can bind this to comboBox as,
//set the data source for the combobox
//and set Display and value
comboBox1.DisplayMember = "Name"; comboBox1.ValueMember = "Id";
//fill ComboBox2 datasource with display member as ID's
and
comboBox1.SelectedIndexChanged += OnSelectedIndexChanged;
on event handler
void OnSelectedIndexChanged(object sender, EventArgs e) { comboBox2.SelectedIndex = comboBox2.Items.IndexOf(((Item)comboBox1.SelectedItem).Id); }Hope this helps you...
BTW, check this post for choosing right forum.
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
- Propuesto como respuesta Shweta Jain viernes, 04 de mayo de 2012 13:43
- Marcado como respuesta Mike FengMicrosoft Contingent Staff, Moderator miércoles, 16 de mayo de 2012 12:26
-
viernes, 04 de mayo de 2012 13:43
Hi sa5000174,
On OnSelectedIndexChanged of combo1, you can do this:
void OnSelectedIndexChanged(object sender, EventArgs e) { comboBox2.SelectedIndex = comboBox2.Items.IndexOf(((Item)comboBox1.SelectedItem).Id); }
Regards, http://shwetamannjain.blogspot.com
- Propuesto como respuesta Shweta Jain viernes, 04 de mayo de 2012 13:43

