|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
prevent control events from firing before form is loadedOften on the form load event I populate combo boxes. When a combo box is populated, the SelectedIndexChanged event fires, sometimes multiple times. Usually the SelectedIndexChanged event runs code which should only run when it is a user selection, not the result of the combo box being populated. What I have been doing is defining a boolean class variable for the form to indicate if the form has loaded completely, and setting it to True when the form is completely loaded, in the form activated event. On each SelectedIndexChanged event I check to see if this boolean variable is true, before executing code. Is this the best way to prevent control events from firing before the form is completely loaded, or if there is a more efficient way? Thanks Bill
Show quote
Hide quote
"BillE" <bel***@datamti.com> wrote in message What I do is to not use the handles clause for those controls and use an news:O1BdFTb7JHA.2456@TK2MSFTNGP02.phx.gbl... >I am working on a vb.net windows forms project using visual studio 2005. > > Often on the form load event I populate combo boxes. > > When a combo box is populated, the SelectedIndexChanged event fires, > sometimes multiple times. > > Usually the SelectedIndexChanged event runs code which should only run > when it is a user selection, not the result of the combo box being > populated. > > What I have been doing is defining a boolean class variable for the form > to indicate if the form has loaded completely, and setting it to True when > the form is completely loaded, in the form activated event. On each > SelectedIndexChanged event I check to see if this boolean variable is > true, before executing code. > > Is this the best way to prevent control events from firing before the form > is completely loaded, or if there is a more efficient way? > > Thanks > Bill > AddHandler after the control has it's data loaded. I use this also in certain cases where I want to refresh the data but not change information on a form about a previously selected item by using a: RemoveHandler PopulateControl AddHandler pattern. Hope this helps LS Delay the wiring up of the event handler.
Remove the 'Handles ...' from your ComboBox_SelectedIndexChanged event handler and, instead, AddHandler ComboBox.SelectedIndexChanged, New EventHandler(Addressof ComboBox_SelectedIndexC]hanged) as the last step in the Form.Load event handler, or, at least, after you have finished initialising the ComboBox. Show quoteHide quote "BillE" <bel***@datamti.com> wrote in message news:O1BdFTb7JHA.2456@TK2MSFTNGP02.phx.gbl... >I am working on a vb.net windows forms project using visual studio 2005. > > Often on the form load event I populate combo boxes. > > When a combo box is populated, the SelectedIndexChanged event fires, > sometimes multiple times. > > Usually the SelectedIndexChanged event runs code which should only run > when it is a user selection, not the result of the combo box being > populated. > > What I have been doing is defining a boolean class variable for the form > to indicate if the form has loaded completely, and setting it to True when > the form is completely loaded, in the form activated event. On each > SelectedIndexChanged event I check to see if this boolean variable is > true, before executing code. > > Is this the best way to prevent control events from firing before the form > is completely loaded, or if there is a more efficient way? > > Thanks > Bill > Thanks!
Bill Show quoteHide quote "BillE" <bel***@datamti.com> wrote in message news:O1BdFTb7JHA.2456@TK2MSFTNGP02.phx.gbl... >I am working on a vb.net windows forms project using visual studio 2005. > > Often on the form load event I populate combo boxes. > > When a combo box is populated, the SelectedIndexChanged event fires, > sometimes multiple times. > > Usually the SelectedIndexChanged event runs code which should only run > when it is a user selection, not the result of the combo box being > populated. > > What I have been doing is defining a boolean class variable for the form > to indicate if the form has loaded completely, and setting it to True when > the form is completely loaded, in the form activated event. On each > SelectedIndexChanged event I check to see if this boolean variable is > true, before executing code. > > Is this the best way to prevent control events from firing before the form > is completely loaded, or if there is a more efficient way? > > Thanks > Bill >
Enable/Disable windows update
vb.net app not finding application configuration file on Windows 2003 Server Standard Not as 'explicit' as I thought --- What am I missing Optional localizing Formatting Text on a textbox Merging Bitmaps Frustrated, Bothered and Bewildered (Form AutoScroll Broken) Help with SOAP3 - OT What are the Versions of Visual Studio 2005 and what Features are Available in Each? Setting DataGridView.Height to Goldilocks value? |
|||||||||||||||||||||||