本文介绍了错误发生datagridviewcomboboxcell值无效使用VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim cmb As New DataGridViewComboBoxCell
cmb.DisplayMember = "Lastname"
cmb.ValueMember = "VendorId"
'''fill dataset using some query having 2 columns lastname and vendorId
dim m_cnDB as new SqlConnection(connectionString)
m_cnDB.Open()
Dim da As New SqlDataAdapter(SQL, m_cnDB)
Dim ds As New DataSet("Results")
da.Fill(ds)
m_cnDB.close()
''adding datasource to comboboxCell
cmb.DataSource = Nothing
cmb.DataSource = ds.Tables(0)
''insert row to datagrid view 3rd column is my combobox column
DataGridView1.Rows.Insert(DataGridView1.NewRowIndex, New Object() {"1", "xyz", cmb})
即使在调试时我也没有在编译时遇到错误。
但是当gridview加载它时会得到ex ception。
系统参数异常:datagridviewcomboboxcell值无效
请帮助找出解决方案
谢谢
I doesn't get error at compile time even while debugging .
but when gridview loads it get exception.
system argument exception: datagridviewcomboboxcell value is not valid
Please help to find out solution
Thank You
推荐答案
With dgv
.AutoGenerateColumns = False
.Columns(1).DataPropertyName = "quantity"
.Columns(2).DataPropertyName = "value_type"
With DirectCast(.Columns(2), DataGridViewComboBoxColumn)
.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox
.ValueMember = "value_type"
.DisplayMember = "value_type_name"
.DataSource = _source
End With
.Columns(3).DataPropertyName = "unit_price"
.DataSource = ds.Tables(1)
End With
如果这有帮助,请花时间接受解决方案。谢谢。
If this helps please take time to accept the solution. Thank you.
这篇关于错误发生datagridviewcomboboxcell值无效使用VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!