質問

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top