Combo box with Multiple Value Member in Win Form

Posted on 2009-12-15
Last Modified: 2013-11-27
Hi Experts,
I have the below codes to populate a combo box and getting Value Member as Vend_cd after combo box selected index change. My problem is a want two values as a Value Member, as i know combo box have single display member and value member. I also know i can conconate two columns and can used as a display member or may be as value member too.

I want to get unit alongwith vend_cd after combobox selected index change event.
How can i do this. Please advise.

     Dim dataset As New DataSet
      Dim adapter As New SqlDataAdapter()
      adapter.SelectCommand = New SqlCommand("select distinct vend_item.vend_Cd,vend_item.Unit,vendor.vend_name from vend_item inner join vendor on vend_item.vend_cd=vendor.vend_Cd where vend_item.item_cd in (" + selectedVendor.ToString + ")", myconn)
  If myconn.State = ConnectionState.Closed Then myconn.Open()
   CmbVendor.DataSource = dataset.Tables(0)
    CmbVendor.DisplayMember = "Vend_name"
     CmbVendor.ValueMember = "Vend_cd"

Bm Keshav
    LVL 1

    Expert Comment

    use for loop for and append the required string and add items

    like cmb.items.add ..
    LVL 11

    Expert Comment

    You can get both the columns in a single combined column from sql query itself and use that combined column as value member.
    select distinct vend_item.vend_Cd + ','+ vend_item.Unit,vendor.vend_name from vend_item inner join vendor on vend_item.vend_cd=vendor.vend_Cd where vend_item.item_cd in (" + selectedVendor.ToString + ")"
    LVL 9

    Accepted Solution

    you can fetch ValueMember by selected value
    for fetch other value you have to make your that DataSet available to whole form
    i mean declare it as a global for that form

    and in selectedindexchange you can find that field like atteched code

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedIndex >= 0 Then
        End If
      End Sub

    Open in new window

    LVL 6

    Author Comment

    @ trideep:
    You are near about to the solution,  but i will check your code, tomorrow, b/c its, 5:47 PM and its time to leave for the day here in India.
    Pl.Also clarify how can i make dataset global in complete form as advised you.

    Bm keshav
    LVL 9

    Expert Comment

    by:Trideep Patel
    Globle to form means
    you have to declare it as a form level insted of declare it in any method or function
    so it can be access from selectionchange event
    LVL 6

    Author Closing Comment

    Thanks for your support.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now