I fill out a ComboBox using below code:
cbxLines.DisplayMember = "Value";
cbxLines.ValueMember = "Key";
cbxLines.DataSource = new BindingSource(GetProductionLines(), null);
private Dictionary<int, string> GetProductionLines()
Now I want to fill out a ListView with every DisplayMember
from the ComboBox among other info:
lvSelectedSetup.Items.Clear();
for (int i = 0; i <= cbxLines.Items.Count - 1; i++)
{
ListViewItem item = new ListViewItem();
item.SubItems.Add(cbxLines.Items[i].ToString()); <-- How to Get DisplayMember
item.SubItems.Add(cbxFromDate.Text);
item.SubItems.Add(cbxToDate.Text);
lvSelectedSetup.Items.Add(item);
}
But I don't know how to get either the ValueMember
or DisplayMember
from the ComboBox.
I was trying doing the following, but get stuck:
item.SubItems.Add(cbxLines.Items[i].GetType().GetProperty(cbxLines.ValueMember).GetValue(cbxLines,null))
Any Advice?
Gets the key in the key/value pair.
((KeyValuePair<int, string>)cbxLines.Items[i]).Key
Gets the value in the key/value pair.
((KeyValuePair<int, string>)cbxLines.Items[i]).Value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.