SelectedIndexChanged problem regarding combobox and data grid
-
Hi, I have just come across a problem where i have a block of code which exercutes when the selectedindexchange event kicks in. However, because i load my form becuase i have a datagrid and the combo box is binded the selectedindexchnage event is exercutes again making duplicate data :( . How do i approach avoiding this? I have looked at diffrent events but cant see one that wil solves my problem, any suggestions or simillar examples anyone can point me to? Many Thanks D.Arnold
dave1816
-
Hi, I have just come across a problem where i have a block of code which exercutes when the selectedindexchange event kicks in. However, because i load my form becuase i have a datagrid and the combo box is binded the selectedindexchnage event is exercutes again making duplicate data :( . How do i approach avoiding this? I have looked at diffrent events but cant see one that wil solves my problem, any suggestions or simillar examples anyone can point me to? Many Thanks D.Arnold
dave1816
If I have a situation where firing an event causes the event to fire again, or similar, I tend to use a flag to tell me when I want the event firing code to run, and when I need to ignore it.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
-
If I have a situation where firing an event causes the event to fire again, or similar, I tend to use a flag to tell me when I want the event firing code to run, and when I need to ignore it.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
Graus is true, but i suggest you to use following when binding comboBox to a data source. you have selected index change event for combo box, you can simply de attach that event before binding comboBox or what ever causes comboBox change index event to fire. i have a combobox named "cmb1" with selectedIndexChangeded named "cmb1ChangedIndex". simply follow this cmb1.selectedIndexChanged -=selectedIndexChangeded; //do binding here for both comboBox or what ever cause comboBox selectedChanged event //to fire then cmb1.selectedIndexChanged +=selectedIndexChangeded ;
-
Hi, I have just come across a problem where i have a block of code which exercutes when the selectedindexchange event kicks in. However, because i load my form becuase i have a datagrid and the combo box is binded the selectedindexchnage event is exercutes again making duplicate data :( . How do i approach avoiding this? I have looked at diffrent events but cant see one that wil solves my problem, any suggestions or simillar examples anyone can point me to? Many Thanks D.Arnold
dave1816
Right never used a flag but will research into it and also go with the bidning solution. Many thanks for you replys I will try the code the solution tonight ( fingers cross it works) I will post a heads up and let you know Thanks again:thumbsup: D.Arnold :-D
dave1816
-
Right never used a flag but will research into it and also go with the bidning solution. Many thanks for you replys I will try the code the solution tonight ( fingers cross it works) I will post a heads up and let you know Thanks again:thumbsup: D.Arnold :-D
dave1816
It worked:thumbsup: Took me a while though to figure out how you put the code togther, but i found a simillar method after about 2 hours of research ,lol. An example of the code i used and found was combobox1.SelectedIndexChanged -= new System.EventHandler(combobox1_SelectedIndexChanged); //here i listed my binding code as you mentioned cboRoomType.SelectedIndexChanged += new System.EventHandler(cboRoomType_SelectedIndexChanged); Works great, does the += method attach the event back to the handler then? i should stupied asking this question as it seem obvious but i want to make sure i know how it works. Many Thanks for you post again D.Arnold :-D p.s. ill be back:suss:lol
dave1816