[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.3

Find ValueMember in ComboBox that is databound from an Array

Asked by si2030 in Microsoft Visual Basic.Net, Microsoft Visual Studio Express, .Net Editors & IDEs

Tags: Visual Basic 2008 with LINQ

Hi there,

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

1000 SMITH
1001 BROWN
etc

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.

MY QUESTION:

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(strFindStr)

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.text)

                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

    With cbxTest
        For aIndex = 0 To .Items.Count - 1
            If CType(.Items(aIndex)(1), String).Trim = cbxTest.Text.Trim Then
                .SelectedIndex = aIndex
                Exit For
            End If
        Next

        If aIndex >= .Items.Count Then .SelectedIndex = -1
    End With

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.

Simon





1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
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, _
                                   clients.last_name, _
                                   clients.client_no).ToArray
 
            With cbxTest
                .DataSource = clientItems
                .DisplayMember = "printPosLastName"
                .ValueMember = "last_name"
                .ValueMember = "client_no"
                .SelectedIndex = 0
            End With
 
            cbxTest.Text = ""
           
        Catch ex As Exception
 
        End Try
 
    End Sub
[+][-]11/10/08 07:04 AM, ID: 22922080Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Microsoft Visual Basic.Net, Microsoft Visual Studio Express, .Net Editors & IDEs
Tags: Visual Basic 2008 with LINQ
Sign Up Now!
Solution Provided By: knk53
Participating Experts: 2
Solution Grade: B
 
[+][-]11/10/08 02:57 PM, ID: 22926520Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/08 04:36 PM, ID: 22927049Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625