Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I searched CP, and could not find anything that was useful. Here is my issue:

I have a custom class, NetworkGroup, representing data on security groups from Active Directory. Nothing fancy, just the display name, description, path and a value stored in extensionattribute10. A second class, NetworkGroupList, inherits from List(Of NetworkGroup).

I am using an instance of NetworkGroupList as the data source for a read-only DataGridView and it works fine, with one annoyance: clicking on the column headers does not sort the data. The SortMode property on the columns are set to Automatic by default; I have gone so far as to set them programmatically. Makes no difference: my class lacks some functionality that allows the grid to auto-sort by column. Similar grids bound to DataTable objects sort just fine, and I have considered manually copying the list into a table and using that, which seems overkill. I have tinkered with the BindableList(Of T) class, with no luck: documentation is very spotty, and for the work involved, it seems that building a data table would be much easier.

Any suggestions on how to proceed?
Posted
Updated 8-Jun-12 5:51am
v2
Comments
Amund Gjersøe 8-Jun-12 17:16pm    
You are looking for an implementation of SortableBindingList<>. There are many examples found on the web. I've used one i pull of the web, and it worked like a charm as long as the properties of T supports IComparable

1 solution

I looked at some of my old projects that use DataGridView and sort nicely.

They all use DataTable

DataTable dt;
DataSet ds;
DataGridView mDgv;
dt=ds.Tables[ixTbl];
mDgv.DataSource =dt;
C#
DataTable dt; 
DataSet ds;
DataGridView mDgv;
dt=ds.Tables[ixTbl];
mDgv.DataSource =dt;


So yes build that DataTable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900