在一个DataGridView动态组合框 [英] Dynamic ComboBox in a DataGridView

查看:144
本文介绍了在一个DataGridView动态组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4列,其中之一是一个下拉列表(组合框)列一个DataGridView。因此,一旦给定的下拉值在一行中选择此列中的值必须是不同的,我想它不以任何其他行的下拉列表中可用。如果给定的值未选中它应该在下拉列表再次显示。我发现类似的例子几篇文章( 1 2 ,的 3 );但是,所有的人似乎涉及订阅事件并手动填充组合框。

I have a DataGridView with 4 columns, one of them being a drop-down (ComboBox) column. The values in this column must be distinct so once a given drop-down values is selected in a row, I'd like it to not be available in any of the drop-downs in other rows. If a given value is unselected it should show up in the drop-downs again. I found a few articles with similar examples (1,2,3); however, all of them seem to involve subscribing to an event and manually populating the ComboBox.


  • 有没有办法单独和绑定完成这个(也许到IEnumerable这基本上是一个 all.Except(选择) Linq查询)?

  • 如果单独数据绑定是不够的,有没有更好的办法做到这一点比我找到的例子吗?

  • Is there a way to accomplish this with databinding alone (maybe to an IEnumerable that's basically a all.Except(selected) Linq query)?
  • If databinding alone isn't enough, is there a better way to do it than the examples I found?

我有点新的WinForms发展,有麻烦告诉来自啊...那会工作,有点除了很好的建议。

推荐答案

恐怕你搜索至今是正确的 - 有没有更好的方式来提供不同的名单在同一DataGridView中列组合框比订阅事件(通常为 CellBeginEdit CellEndEdit ,然后设定DataSource的单个的DataGridViewComboBoxCell )。

I'm afraid your searching so far is correct - there is no better way to provide different lists to comboboxes in the same DataGridView column than subscribing to events (usually CellBeginEdit and CellEndEdit and then setting the DataSource for an individual DataGridViewComboBoxCell).

通过的这方面的证据的方式,我会指示你的优秀的 DataGridView的常见问题解答写由微软DataGridView的项目经理Mark赖德奥特。常见问题有一个完整的解决您的问题,这是非常相似,您发布的链接。

By way of evidence of this, I'll point you to the excellent DataGridView FAQ which was written by Mark Rideout, the DataGridView program manager at Microsoft. The FAQ has a full solution to your problem which is very similar to the links you post.

这篇关于在一个DataGridView动态组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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