HLP: GRRR... StartUp Troubles

  • Thread starter Thread starter Mr. B
  • Start date Start date
M

Mr. B

GRRRR... I've run across a situation in which I have NO solution. Hopefully
there is one. VB.net.

It's rather simple.

I've a ComboBox that get's populated via a Database. And I pre-select (during
Formload) the Index using SelectedIndex:

' Get User info from Data Base fill
daPickUser.Fill(dsPickUser.MASTER_PRM_EMPLOYEE)
cmbUserName.SelectedIndex = cmbUserName.FindStringExact(strUserID)

Now the above works just fine. It finds my strUserID (ie: FEU001 which is
Index #28) and that is what is listed in the ComboBox on startup. Great!

However, I want to use the Combobox to select another User at some time. When
I ENABLE the following Private Sub for the Combobox, I get my troubles...

My Combobox even is thus...

Private Sub cmbUserName_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbUserName.SelectedIndexChanged

dsTimberline.tblTimeEntry.Clear()
' Refresh the Data Grid with New User Selected
strUserID = cmbUserName.Text
daTimberline.SelectCommand.Parameters(0).Value = strUserID
daTimberline.Fill(dsTimberline.tblTimeEntry)

End Sub


What happens is that on startup, somehow the Combobox SelectedIndexChanged
sets my Combobox Index to Zero (0)... every time. I don't want Index of 0.
But the listing of what is the Index number of my strUserID.

How can I prevent the cmbUserName_SelectedIndexChanged from being triggered
during startup???

Regards,

Bruce
 
GRRRR... I've run across a situation in which I have NO solution. Hopefully
there is one. VB.net.

It's rather simple.

I've a ComboBox that get's populated via a Database. And I pre-select (during
Formload) the Index using SelectedIndex:

' Get User info from Data Base fill
daPickUser.Fill(dsPickUser.MASTER_PRM_EMPLOYEE)
cmbUserName.SelectedIndex = cmbUserName.FindStringExact(strUserID)

Now the above works just fine. It finds my strUserID (ie: FEU001 which is
Index #28) and that is what is listed in the ComboBox on startup. Great!

However, I want to use the Combobox to select another User at some time. When
I ENABLE the following Private Sub for the Combobox, I get my troubles...

My Combobox even is thus...

Private Sub cmbUserName_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbUserName.SelectedIndexChanged

dsTimberline.tblTimeEntry.Clear()
' Refresh the Data Grid with New User Selected
strUserID = cmbUserName.Text
daTimberline.SelectCommand.Parameters(0).Value = strUserID
daTimberline.Fill(dsTimberline.tblTimeEntry)

End Sub


What happens is that on startup, somehow the Combobox SelectedIndexChanged
sets my Combobox Index to Zero (0)... every time. I don't want Index of 0.
But the listing of what is the Index number of my strUserID.

How can I prevent the cmbUserName_SelectedIndexChanged from being triggered
during startup???

Regards,

Bruce

Bruce...

A possilbe solution to this is to remove the handles clause from your
event handler. Then AFTER you fill the combobox, you can associate the
event with the combobox using AddHandler:

Private Sub Form_Load(...) Handles...

' Fill Your Combo Box

' Add your handler dynamcially
AddHandler cmbUserName.SelectedIndexChanged, AddressOf
cmbUserName_SelectedIndexChanged
End Sub


' then change the sig of the event to:
Private Sub cmbUserName_SelectedIndexChanged( _
ByVal sender As System.Object, ByVal e As System.EventArgs)

'Do Cool Stuff!
End Sub

HTH
 
With Deft Fingers said:
A possilbe solution to this is to remove the handles clause from your
event handler. Then AFTER you fill the combobox, you can associate the
event with the combobox using AddHandler:

Thanks Tom... I'll try that!

Regards,

Bruce
 
With Deft Fingers said:
A possilbe solution to this is to remove the handles clause from your
event handler. Then AFTER you fill the combobox, you can associate the
event with the combobox using AddHandler:

Sweet!!! Worked GREAT! Many Thanks!

Bruce
 
Back
Top