开发者

c# listBox DisplayMember

开发者 https://www.devze.com 2023-01-21 12:31 出处:网络
c# WinForms.Listbox. listBox1.DataSource = ds.Tables[0].DefaultView; listBox1.DisplayMember = \"Question\";

c# WinForms.Listbox.

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

//for ValueMember sh开发者_如何学运维owing...   
textBox2.Text = listBox1.SelectedValue.ToString();

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


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]


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

0

精彩评论

暂无评论...
验证码 换一张
取 消