用亚音速和; 填充 datagridview 组合框列 VB.Net
就像标题所说,我正在尝试填充 datagridview 中的组合框列。
到目前为止,这是我所拥有的:
Dim lc As System.Web.UI.WebControls.ListItemCollection = _
DataAccess.Part.GetListItems()
dgvcboPart.DataSource = lc
' This is a standalone combo box and it works ok
cboTest.DataSource = lc
对于我缺少的内容有什么建议吗?
谢谢 托尼·W
Like the title says, I'm trying to populate a combo box column in a datagridview.
Here's what i have so far:
Dim lc As System.Web.UI.WebControls.ListItemCollection = _
DataAccess.Part.GetListItems()
dgvcboPart.DataSource = lc
' This is a standalone combo box and it works ok
cboTest.DataSource = lc
Any suggestions as to what I'm missing ?
Thanks
Tony W
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我首先建议您将 Collection 绑定到 BindingSource,然后将 BindingSource 添加到 DataGridView (这样您就知道位置),
但是绑定 ComboBoxCell 应该非常简单。
假设您有一个包含 Id 和 Name 两列的 DataTable tblCurrency。
您必须将其绑定到您的列(我假设第 0 列是您的 DataGridViewColumn)
然后您可以将 DataPropertyName 设置为数据源中的属性。
小心,tblCurrency.Id和Currency_Id必须是相同的类型(Int32和UInt32不起作用),如果Currency_Id有一个不在tblCurrency中的值,你会得到一个带有完整StackTrace的令人讨厌的MessageBox(所以你应该处理DataError)事件)
I first suggest you bind your Collection to a BindingSource and then add the BindingSource to the DataGridView (so you know the position)
But binding a ComboBoxCell should be pretty much straight forward.
Let's say you have a DataTable tblCurrency containing two columns Id and Name.
You have to bind this to your Column (I assume Column 0 ist your DataGridViewColumn)
Then you can set the DataPropertyName to the Property in your DataSource.
Be carful, tblCurrency.Id and Currency_Id have to be of the same Type (Int32 and UInt32 does not work) And you get a nasty MessageBox with a full StackTrace if Currency_Id has a value that is not in tblCurrency (so you should handle the DataError event)
必须调用数据绑定方法才能发生奇迹!
have to call the databind method for the magic to happen!