Click here to Skip to main content
15,889,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Form_load() 
cn.Open()
 Dim cmd As New SqlCommand("select IDUser,Name from Users   ", cn)
   Dim da As New SqlDataAdapter(cmd)
   Dim ds As New DataSet
   da.Fill(ds, "t")
   cmb.DataSource = ds.Tables("t")
   cmb.DisplayMember = "Name"
   cmb.ValueMember = "IDUser"
   'cm
   DataGridView3.Columns.Add(cmb) 
cn.close
button_getID()
'This code does not work
dim idUser as string
idUser=cmb.selectedValue

I want to get IdUser from Combobox exist in DataGridView when I selecte a Name user in Combobox.
Please help me. and thank you so much!!!
Posted

You need to indicate which ComboBox you are looking at - remember that cmb is a DataGridViewComboBoxColumn
VB
button_getID()
    'Assuming the ComboBox column is the first one ...
    Dim cmbc As DataGridViewComboBoxCell = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0)

    Dim idUser as String
    idUser=cmbc.Value
End Sub
 
Share this answer
 
These code is working ,Thank you so much.... !!!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900