My problem relates to a standard comboBox.
First, what I am trying to acomplish....
I have a label and then a comboBox next to each other. The comboBox displays a dropdown of a client number and the client last name. they are concatinated eg
What I want is to search the drop down on the name ONLY, not the client number. That is Type in an "S" and immediately the combobox would display SMITH with the MITH being the highlighted area. If I leave the comboBox the selected index will use the clientNo for that row and populate the label next to the combobox.
So the Combobox has the concatenated clientNo and lastName but the combobox.text shows just the name and if i leave I get the clientNo in the label.
OK so I used a LINQ comand to pick up all the clients and create an array that has effectively THREE columns and then add this to the combobox. THIS WORKS. eg I get a comboBox that has the correct display member (and I assume two value members). See the added code area.
I wanted to use "findString" to match the string entered into the comboBox to the VALUE MEMBER not the display member. The following only tests on the display member that has as its first 5 digits the client number (as above).
intIdx = cbxTest.FindString(strFind
The fact is I want to use this on the VALUE MEMBER - "Last_name" not the display member - "printPosLastName"... or alternatively code that does the same test. At the moment I cannot even get the system to recognise the value member... I am using this to create an autocomplete subroutine along the lines of:
intIdx = cbxTest.FindString(cbxTest
If intIdx <> -1 Then ' String found in the list.
cbx.SelectedText = ""
cbx.SelectedIndex = intIdx
cbx.SelectionStart = strFindStr.Length
cbx.SelectionLength = cbx.Text.Length
I also tried this but I am guessing it will match a full row not a partial match - it doesnt work anyway:
Dim aIndex As Integer
For aIndex = 0 To .Items.Count - 1
If CType(.Items(aIndex)(1), String).Trim = cbxTest.Text.Trim Then
.SelectedIndex = aIndex
If aIndex >= .Items.Count Then .SelectedIndex = -1
I get the following error: "No default member found for type 'VB$AnonymousType_0(Of String,String,Integer)'." on the IF Ctype(.items.....
Hope I have explain this correctly and given enough for you to follow.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim clientItems = (From clients In db.clients _
Order By clients.last_name _
Select printPosLastName = clients.client_no & " " & clients.last_name, _
.DataSource = clientItems
.DisplayMember = "printPosLastName"
.ValueMember = "last_name"
.ValueMember = "client_no"
.SelectedIndex = 0
cbxTest.Text = ""
Catch ex As Exception