Alternatively, you could remove the handler of the event before you assign
the datasource and then reattach it after you're done.
So you can modify your code to do this:
'
' Remove the handler
'
RemoveHandler cboTest.SelectedValueChanged, AddressOf
cboTest_SelectedValueChanged
'
' Bind the data
'
Me.cboTest.DataSource = myTable
Me.cboTest.DisplayMember = "FieldDisplayName"
Me.cboTest.ValueMember = "FieldID"
'
' Re-attach the handler
'
AddHandler cboTest.SelectedValueChanged, AddressOf
cboTest_SelectedValueChanged
--
Bits. Bytes.
http://bytes.thinkersroom.com
------------------------------
"Morten Wennevik" wrote:
> Interesting, it seems that ValueChanged fires whenever you set the
> DataSource, DisplayMember or ValueMember. I'm not sure you can avoid
> firing the event, but you can use a flag to determine when to not process
> the event.
>
>
> ignoreFlag = True
> Me.cboTest.DataSource = myTable
> Me.cboTest.DisplayMember = "FieldDisplayName"
> Me.cboTest.ValueMember = "FieldID"
> ignoreFlag = False
>
>
> And in your event
>
> If(ignoreFlag)
> Return
> End If
>
>
> On Wed, 15 Nov 2006 11:46:03 +0100, Neil Steventon
> <(E-Mail Removed)> wrote:
>
> > I basically read the values with a reader from SQL and then create a
> > datatable. I then make the combo box reference the table.
> >
> > Example code.
> > Do while myReader.Read
> > Dim currentRow as DataRow = myTable.NewRow
> > currentRow("FieldID") = myReader("FieldID")
> > currentRow("FieldDisplayName") = myReader("FieldDisplayName")
> > myTable.Rows.Add(currentRow)
> > Loop
> >
> > ME.cboTest.DataSource = myTable
> > Me.cboTest.DisplayMember = "FieldDisplayName"
> > Me.cboTest.ValueMember = "FieldID"
> >
> >
> > Thanks
> >
> > Neil
> >
> > "Morten Wennevik" wrote:
> >
> >> Hi Neil,
> >>
> >> Just filling the ComboBox with values shouldn't fire any
> >> SelectedValueChanged event. How are you filling it?
> >>
> >>
> >>
> >> On Wed, 15 Nov 2006 10:53:01 +0100, Neil Steventon
> >> <(E-Mail Removed)> wrote:
> >>
> >> > Hi fill a combo box with items as the form loads but this calles the
> >> > SelectedValueCahnged event. I dont want it to call the event until I
> >> > select a
> >> > value in the combo box, whats the best way around the problem.
> >> >
> >> > I think I can get around it by adding the handler after I have
> >> populated
> >> > the
> >> > data, but just wondering if there is a better solution.
> >>
> >>
> >>
> >> --
> >> Happy Coding!
> >> Morten Wennevik [C# MVP]
> >>
>
>
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]
>