I am creating a winforms application in visual studio 2017, I am populating a ListView using a
List<KeyValuePair<string, string>>
Examples of the data are:
List<KeyValuePair<ABC, 123>>
List<KeyValuePair<ABC, 456>>
List<KeyValuePair<ABC, 789>>
List<KeyValuePair<DEF, 123>>
List<KeyValuePair<DEF, 233>>
I try to diplay this in a ListView, where I would like to have sometihng like this:
ABC
- 123
- 456
- 789
DEF
- 123
- 233
Where the ABC and the DEF are selectable only. I try to write a code to do this, but unfortunately it only displays the ABC and DEF without the subitems.
The code I wrote is:
workOrderClusters = GetItac.FilterWorkOrderClusters();
// GetItac.FilterWorkOrderClusters() is a
List<KeyValuePair<string,string>>
string current; string previous,
foreach (var workOrderCluster in workOrderClusters)
{
current = workOrderCluster.Key;
if (current != previous)
{
var listViewItem = new ListViewItem(workOrderCluster.Key);
foreach (var cluster in workOrderClusters)
{
if (cluster.Key == current)
{
listViewItem.SubItems.Add(cluster.Value);
}
}
}
previous = current;
listView1.Items.Add(listViewItem);
My question is, is there anyway to make the ListView display as expected ?