如何在DataGridView中获取组合框的selectedValue
问题描述:
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
当我在Combobox中选择一个名字用户时,我希望从DataGridView中获得来自Combobox的IdUser。
请帮助我。非常感谢!!!
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!!!
答
您需要指出您正在查看的ComboBox - 记住cmb
是一个DataGridViewComboBox 列
You need to indicate which ComboBox you are looking at - remember thatcmb
is a DataGridViewComboBoxColumn
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
这些代码正常运行,非常感谢.... !!!!!
These code is working ,Thank you so much.... !!!!!