• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3191
  • Last Modified:

Combo box with Multiple Value Member in Vb.net Win Form

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()
  adapter.Fill(dataset)
   myconn.Close()
   CmbVendor.DataSource = dataset.Tables(0)
    CmbVendor.DisplayMember = "Vend_name"
     CmbVendor.ValueMember = "Vend_cd"

Bm Keshav
0
BALMUKUND KESHAV
Asked:
BALMUKUND KESHAV
1 Solution
 
vinodpakaCommented:
use for loop for and append the required string and add items

like cmb.items.add ..
0
 
ROMA CHAUHANProject LeadCommented:
You can get both the columns in a single combined column from sql query itself and use that combined column as value member.
like...
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 + ")"
0
 
Trideep PatelCommented:
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
      MessageBox.Show(ds.Tables(0).Rows(ComboBox1.SelectedIndex).Item("EmpSal"))
    End If
  End Sub

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
BALMUKUND KESHAVAuthor Commented:
@ 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
0
 
Trideep PatelCommented:
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
0
 
BALMUKUND KESHAVAuthor Commented:
Thanks for your support.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now