0
listBox2.DataSource = listBox1.SelectedItems;
listBox2.DisplayMember = "Descripcion";
listBox2.ValueMember = "Id";

上記のコードを使用した後、1 つずつ選択できません。ヘルプ!誰かがコードを投稿して削除してください

4

3 に答える 3

1

まず、 Listbox のモデルを定義する必要があります:

public class MyModel
{
    public int Id { get; set; }
    public string Description { get; set; }
}

このような項目を設定した後:

listBox2.Items.Add(new MyModel() { Id = 1, Description = "description" });
listBox2.DisplayMember = "Description";
listBox2.ValueMember = "Id";

これで、リストボックスに description プロパティが表示されます。項目を選択すると、listbox2 の SelectedValue が id プロパティの値になります

于 2013-03-05T14:52:38.103 に答える
0
    if (listBox1.SelectedItem != null)
        {
            listBox2.Items.Add(listBox1.SelectedItem);
        }
        listBox2.DisplayMember = "Descripcion";
        listBox2.ValueMember = "Id";

これはうまくいっています....

于 2013-03-05T15:21:42.013 に答える
0

SqlDataAdapter を使用してデータ ソースからリストボックスにデータをダンプし、リストボックスの 1 つで選択されたデータに基づいて listbox.add() メソッドを使用します。「for」ループを使用して、インデックスを使用して 1 つのリストボックスから別のリストボックスにデータをダンプします。

for(int i=0; i<listBox1.SelectedItems.Count; i++)
{
    listBox2.Items.Add(listbox1.SelectedItems[i].toString());
}
于 2013-03-05T15:10:24.457 に答える