[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Bound Combobox and Valuemember

Posted on 2009-04-22
13
Medium Priority
?
318 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:sprintdata
  • 6
  • 4
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24210279
Try using this syntax

combobox1.selectedindex = combobox1.findstringex("text to search")
0
 

Author Comment

by:sprintdata
ID: 24213097
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24213130
If you have a value then you can set the selectedvalue directly i think using

combobox1.SelectedValue = value
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:sprintdata
ID: 24215819
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24216152
Does it help if you remove the Val function?
0
 

Author Comment

by:sprintdata
ID: 24218739
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24219996
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
 

Accepted Solution

by:
sprintdata earned 0 total points
ID: 24224039
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24224062
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24224771
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question