DataGridView中的动态ComboBox [英] Dynamic ComboBox in a DataGridView
问题描述
- 有没有办法用数据绑定来完成这个(可能是一个IEnumerable,基本上是一个
all.Except(selected)
Linq query)? - 如果单独的数据绑定还不够,有没有比我发现的例子更好的方法?
我对WinForms开发有一点新意有麻烦的是从是的,这将会起作用中分开好的建议。
我恐怕你的搜索到目前为止是正确的 - 没有更好的方法来提供不同的列表到组合框在同一个DataGridView列比订阅事件(通常 CellBeginEdit
和 CellEndEdit
然后为单个 DataGridViewComboBoxCell
设置DataSource。
。DataGridView常见问题的样例/ Go%2520至%2520Market / DataGridView / DataGridView%2520FAQ.doc& ei = anuLTtL4GMjHtAbVotyTAg& usg = AFQjCNFxVe3EWtsJNP7xXxff6dxU0EQrel =nofollow> DataGridView FAQ 。常见问题解答与您发布的链接非常相似。
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.
- 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?
I'm a bit new to WinForms development so having trouble telling apart good advice from "yeah...that'll work, sort of".
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
).
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中的动态ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!