Bound Combobox and Valuemember

Hello

I am trying to do something within VB.Net 2008 that i had no trouble in VB6. I have a bound combobox that displays communication methods in text, in value member i have the Communications ID number.

I have a datagrid bound to another table 'Terminals' which has a field call CommsMethod which stores a number that equates to value member in the combobox.

As i move from record to record the bound textfields change appropriately but i am trying to get the combobox to show the appropriate communications method associated with the displayed record.
Its a matter of determining the SelectedIndex but the examples on EE that i have tried do not give me the result that i am looking for or else cause difficult to resolve errors.

Youir suggestions would be appreciated.
Edward CooperDirectorAsked:
Who is Participating?
 
Edward CooperConnect With a Mentor DirectorAuthor Commented:
Brilliant..just what was wanted. iused the TextChanged event in the end as i was not able to add the CurrentChange event to teh Binding Source although i would have prefferred that route. i couldn't figure out really what went where..something to learn there. Thanks for your help I will issue to you the points.

Cheers
0
 
CodeCruiserCommented:
Try using this syntax

combobox1.selectedindex = combobox1.findstringex("text to search")
0
 
Edward CooperDirectorAuthor Commented:
Hi

Unfortunately this suggestion doesn't work and i guess its because that this method is looking to compare the value that is stored in the Display member whereas my number reference is actually in the valuemember

PS
FindStringEx is not a member but i guess it should be FindStringExact
 cboCommMethod.SelectedIndex = cboCommMethod.FindStringExact(CommMethodTextBox.Text)

Any other suggestions to get comparison with Valuemember and return the SelectedIndex?


Thanks
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
CodeCruiserCommented:
If you have a value then you can set the selectedvalue directly i think using

combobox1.SelectedValue = value
0
 
Edward CooperDirectorAuthor Commented:
When the form initially opens it gives teh correct result but as i move to another record it doesn't change but does the next move but is out of sync. It appears that the fire event position being applied is wrong i have placed this code in
 Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click

        cboCommMethod.SelectedValue = Val(CommMethodTextBox.Text)

 End Sub

Private Sub BindingNavigatorMovePreviousItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMovePreviousItem.Click

        cboCommMethod.SelectedValue = Val(CommMethodTextBox.Text)

End Sub

Private Sub BindingNavigatorMoveFirstItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveFirstItem.Click

            cboCommMethod.SelectedValue = Val(CommMethodTextBox.Text)

End Sub

Private Sub BindingNavigatorMoveLastItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveLastItem.Click


   cboCommMethod.SelectedValue = Val(CommMethodTextBox.Text)

End Sub

Private Sub BindingNavigatorMovePreviousItem_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BindingNavigatorMovePreviousItem.MouseUp

   cboCommMethod.SelectedValue = Val(CommMethodTextBox.Text)

End Sub

 Private Sub BindingNavigatorMoveNextItem_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BindingNavigatorMovePreviousItem.MouseUp

   cboCommMethod.SelectedValue = Val(CommMethodTextBox.Text)

End Sub

I wanted to try and use the suggested code when  the associated textbox text event is changed but have some trouble getting that to do anything.

Tx  
0
 
CodeCruiserCommented:
Does it help if you remove the Val function?
0
 
Edward CooperDirectorAuthor Commented:
Hi CodeCruiser i appreciate your assistance by the way but i am still not having any success it still insists on showing the CommType in teh combobox from the previous record and not the current one.

0
 
CodeCruiserCommented:
Now that you said it shows previous record then i can see that the problem is not setting the value but setting the CURRENT value. I think the reason is that you set the selectedvalue before the record actually is moved.  If you have a BindingSource control, move the SelectedValue code to the CurrentChanged event of the BindingSource. Otherwise move the code to CommMethodTextBox_TextChanged event.
0
 
CodeCruiserCommented:
That is not the correct way of issueing points i am affraid. You have closed the question without accepting an answer. To award the points, you need to click on Accep Answer button next to the comment which was helpful. I will ask the moderators cancel the deletion and help you accept the answer correctly.
0
 
CodeCruiserCommented:
Modus_operandi,
In my careful understanding, closing the question and accepting the answer are two different things. My comment was not selected as the answer and the author had initiated closing of the question. Does it mean i still get the points? Why not select my comment as answer and just close the question?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.