如何在DataGridView中获取组合框的selectedValue [英] How to Get selectedValue of combobox in DataGridView
本文介绍了如何在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.... !!!!!
这篇关于如何在DataGridView中获取组合框的selectedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文