填充一个datagridview组合框列与亚音速& vb.net [英] populating a datagridview combobox column with subsonic & vb.net

查看:156
本文介绍了填充一个datagridview组合框列与亚音速& vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我到目前为止的这个目录:

  Dim lc As System.Web.UI.WebControls.ListItemCollection = _ 
DataAccess.Part.GetListItems()

dgvcboPart.DataSource = lc

'这是一个独立的组合框,它的工作正常
cboTest.DataSource = lc

关于我失踪的任何建议?



感谢
Tony W

解决方案

我首先建议您将您的集合绑定到BindingSource,然后将BindingSource添加到DataGridView(所以你知道位置)



但是绑定一个ComboBoxCell应该是非常简单的。



假设你有一个包含两列Id和Name的DataTable tblCurrency。
你必须绑定到你的列(我假设列0是你的DataGridViewColumn)

  dgvcboPart.Columns(0 ).DataSource = tblCurrency 
dgvcboPart.Columns(0).ValueMember =Id
dgvcboPart.Columns(0).DisplayMember =Name
pre>

然后可以将DataPropertyName设置为DataSource中的属性。

  dgvcboPart.Columns(0).DataPropertyName =Currency_Id

Be carful,tblCurrency.Id和Currency_Id必须是相同的类型(Int32和UInt32不起作用)如果Currency_Id的值不在tblCurrency(所以你应该处理DataError事件),你会收到一个满满的StackTrace的令人讨厌的MessageBox。


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

解决方案

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)

     dgvcboPart.Columns(0).DataSource = tblCurrency
     dgvcboPart.Columns(0).ValueMember = "Id"
     dgvcboPart.Columns(0).DisplayMember = "Name"

Then you can set the DataPropertyName to the Property in your DataSource.

     dgvcboPart.Columns(0).DataPropertyName = "Currency_Id"

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)

这篇关于填充一个datagridview组合框列与亚音速& vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆