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?