0

したがって、コンボボックスには、、、、および空白の選択が必要な場合に必要な1つの要素を含むリストを含むdataSourceコンボボックスを使用します。今、コンボボックスを開くと、次のように表示されます。IDName

ここに画像の説明を入力してください

--No Material--そのようなリストから来ています:

materialTypes.Insert(0, "-- No Material --");

必要ですがID's、名前はLinqクエリで生成された別のリストから取得されているため、IDを非表示にします。アプローチがわかりません。不要なデータを非表示にするか、必要なデータを明示的にマークします。しかし、私はこれら2つのことのどちらを行うかわかりません。

PSこれはコンボボックスのコード全体です:

 IList<String> materialTypes =  ((from tom in context.MaterialTypes
                                                where tom.IsActive == true
                                                select tom.Name)
                                           .Union(from tom in context.MaterialTypes
                                           where tom.IsActive == true
                                           select SqlFunctions.StringConvert((double)tom.ID))).ToList();

            materialTypes.Insert(0, "-- No Material --");
            cboTypeOfMaterial.DataSource = materialTypes;
4

1 に答える 1

1

あなたのクエリを見ると、それは少し奇妙です、私はそれを次のようにします:

IList<MaterialType> materialTypes =  (from tom in context.MaterialTypes
                                      where tom.IsActive == true
                                      select tom).ToList(); //do you really need to split ID's from Names?

materialTypes.Insert(0, new MaterialType { Name = "-- No Material --" }); //add to our list fake material

combobox.ValueMember = "ID";
combobox.DisplayMember = "Name";
combobox.DataSource = materialTypes;
于 2013-02-22T12:28:12.003 に答える