Click here to Skip to main content
14,175,390 members
Rate this:
 
Please Sign up or sign in to vote.
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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;
DataTable dt; 
DataSet ds;
DataGridView mDgv;
dt=ds.Tables[ixTbl];
mDgv.DataSource =dt;


So yes build that DataTable.
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190524.3 | Last Updated 8 Jun 2012
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100