Reputation: 29431
In my app, I display a listview
with a few entries. I can group them by groups and it works well.
When I do the same in Excel/MatLab via the API I created (based on the same code) the groups doesn't work, see pictures:
In the application:
And in the API:
As you can see, it doesn't work. Here's the code I use:
// Sets the ListView to the groups created for the specified column.
private void SetGroups(Hashtable groups,int column)
{
// Remove the current groups.
listView1.Groups.Clear();
// Copy the groups for the column to an array.
ListViewGroup[] groupsArray = new ListViewGroup[groups.Count];
groups.Values.CopyTo(groupsArray, 0);
// Sort the groups and add them to the ListView.
Array.Sort(groupsArray, new ListViewGroupSorter(listView1.Sorting));
listView1.Groups.AddRange(groupsArray);
// Iterate through the items in the ListView, assigning each
// one to the appropriate group.
foreach (ListViewItem item in listView1.Items)
{
// Retrieve the subitem text corresponding to the column.
string subItemText = item.SubItems[column].Text;
// For the Title column, use only the first 3 letters.
if (column == 0)
{
subItemText = subItemText.Substring(0,3);
}
// Assign the item to the matching group.
item.Group = (ListViewGroup) groups[subItemText];
}
}
How can I fix this?
Upvotes: 0
Views: 144
Reputation: 125197
Put Application.EnableVisualStyles();
in constructor of form:
public Form1()
{
InitializeComponent();
Application.EnableVisualStyles();
}
Upvotes: 1