|
-
Sep 3rd, 2012, 11:31 AM
#1
Thread Starter
Frenzied Member
Btn Click
Hi,
I have the following code;
Code:
Private Sub BtnChk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnChk.Click
'TODO: This line of code loads data into the 'ProductDetails.QryProductDetails' table. You can move, or remove it, as needed.
Me.QryProductDetailsTableAdapter.Fill(Me.ProductDetails.QryProductDetails, TxtTruckTyp.Text, TxtModel.Text, TxtCategory.Text)
Me.TblTruckTypeTableAdapter.Fill(Me.TruckTyp.TblTruckType)
CmbTruckTyp.SelectedIndex = CmbTruckTyp.FindStringExact(TxtTruckTyp.Text)
End Sub
At run time, I click the button and it works ok. Th ereason I inserted the code in BOLD is to refresh the combo box (CmbTruckTyp) and retain the selectedIndex by reading it again from TxtTruckTyp.
Reason why I am doing this is because at run time if I do multiple selection from the combo box the value keep duplicating itself in the dropdownlist and I wanted to avoid that.
The problem am facing now is no duplication, however, at when I click the button the cmbTruckTyp becomes blank until you select again. ie.,
Code:
CmbTruckTyp.SelectedIndex = CmbTruckTyp.FindStringExact(TxtTruckTyp.Text)
doesnt take effect..
Any help please
thanks
-
Sep 3rd, 2012, 12:15 PM
#2
Addicted Member
Re: Btn Click
Hi Dr223
CmbTruckTyp.SelectedIndex relates to the Actual position of each item. This will be an integer
imagine it like
index Item
0 I1
1 I2
2 I3
3 I4
i think you want CmbTruckTyp.SelectedItem
Hope this helps
Ian
Ian
-
Sep 4th, 2012, 04:15 AM
#3
Thread Starter
Frenzied Member
Re: Btn Click
Ok Tried;
Code:
Me.TblTruckTypeTableAdapter.Fill(Me.TruckTyp.TblTruckType)
CmbTruckTyp.SelectedItem = CmbTruckTyp.FindStringExact(TxtTruckTyp.Text)
Now, it refreshes the combo box but doesnt have the selecteditem prior to the refresh, instead it selects the top value of the dropdownlist.
Therefore, for test purposes I removed...
Code:
CmbTruckTyp.SelectedItem = CmbTruckTyp.FindStringExact(TxtTruckTyp.Text)
I noticed that when the combo box is refreshed TxtTruckTyp.Text is then set to BLANK, WHY? So then I tried to remove ;
Code:
Me.TblTruckTypeTableAdapter.Fill(Me.TruckTyp.TblTruckType)
Now, the TxtTruckTyp.Text retains the selecteditem of the CmbTruckTyp.
Therefore, could the problem be
Code:
Me.TblTruckTypeTableAdapter.Fill(Me.TruckTyp.TblTruckType)
and if so why will it affect the textbox while it should only be refreshing the combo box?
Thanks
-
Sep 6th, 2012, 03:42 AM
#4
Addicted Member
Re: Btn Click
when you fill a combo box it will make selections and if you have code in CmbTruckTyp.selectedindexchanged or any of those it will run that code
when you bind data to a combox i find it necessary to have a boolean called something like initilising. make it true before you bind it and then false when its bound, then in the CmbTruckTyp.anythingchanged you'll want something like
Code:
if initilising = true then exit sub
this will stop code being run before you want it to
Ian
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|