0

このコードで:

comboBoxCurrently.DataSource = PlatypusData.getCurrentlyVals();
comboBoxCurrently.Items.Remove("Surrounded by purplish-blue Penguins");

...「System.ArgumentException was unhandled Message=Items collection cannot be modified when the DataSource property is set.」というメッセージが表示されます。

後でクエリ内から削除する値 ( ...WHERE bla <> 'Surrounded... )を制限したくありません。その値が (履歴データを表示するために) 許可されている場合があるためです。 getCurrentlyVals()に条件付きステートメントが必要なのは、どちらか一方のクエリ ステートメントを使用する場合です (より良い方法がある場合)。

何か案は?

更新しました

OK、これはうまくいきました:

List<string> intermediateList = PlatypusData.getCurrentlyVals();
intermediateList.Remove("Surrounded by purplish-blue Penguins");
comboBoxCurrently.DataSource = intermediateList;

再度更新

私はそれをLarsの方法に変更しました:

comboBoxCurrently.Items.AddRange(PlatypusData.getCurrentlyVals().ToArray());
comboBoxCurrently.Items.Remove("Surrounded by purplish-blue Penguins");

...そして、このページには、過去または未来の人類の歴史のどのページよりも多くの文字列「紫がかった青のペンギンに囲まれている」のインスタンスがあると思います。

4

2 に答える 2

2

omboBoxCurrently.DataSource をパブリック プロパティにバインドする

例えば

Public ObservableCollection<string> AnimalList { get; set; }

Ctor AnimalList = PlatypusData.getCurrentlyVals(); で

次に、AnimalList.Remove("紫がかった青のペンギンに囲まれています");

于 2012-07-25T20:38:39.980 に答える
1

DataSource からコレクションを変更する必要がありますが、それを行うことに反対しているようです。その場合は、DataSource を使用せずに、アイテムを ComboBox に直接追加してみてください。

comboBoxCurrently.Items.AddRange(PlatypusData.getCurrentlyVals().ToArray());
comboBoxCurrently.Items.Remove("Surrounded by purplish-blue Penguins");
于 2012-07-25T20:58:07.083 に答える