c# listBox DisplayMember

2019-08-07 18:39发布

c# WinForms.Listbox.

listBox1.DataSource = ds.Tables[0].DefaultView;
listBox1.DisplayMember = "Question";
listBox1.ValueMember = "idQuestion";

//for ValueMember showing...   
textBox2.Text = listBox1.SelectedValue.ToString();

//What I must use for DisplayMember showing?  
textbox3.Text = ??????????

2条回答
虎瘦雄心在
2楼-- · 2019-08-07 19:05

This will work with you
textbox3.Text = listBox1.GetItemText(listBox1.SelectedItem);

查看更多
淡お忘
3楼-- · 2019-08-07 19:07

That may not be so easy with untyped tables. A Combobox has a Text property, for the listbox:

 textbox3.Text = listBox1.SelectedItem;

Gets you the 'item' but that probably is a DataRowView. You can cast it :
((DataRowViw) SelectedItem).Row[3]

查看更多
登录 后发表回答