datagridview column sort question

J

JvCoach23

I'm using a windows form in Vb.net 2.0.

I have a datagridview that is populated with data. It is for viewing
only, i have turned of allowing edits, adding, deleteing and column
reorg. when i click on the datagridview and go to edit columns and
select a column and look at the SortMode, it's set to automatic.
However, when i run the app and click on that column (with data in the
grid) it doesn't sort, it doesn't have the little markers on the column
header either. I understand that you can code behind to get the data
to sort, but I was thinking this was suppose to work as well. anyone
know what I'm not doing. seems if the sortmode is on automatic it
should sort them. The columns i'm talking about are textbox columns.
I have a bindingsource that was created when i drub a data source
object onto the form. the data source object was a object.

thanks for the help
shannon
 
C

Chris Jobson

JvCoach23 said:
I'm using a windows form in Vb.net 2.0.

I have a datagridview that is populated with data. It is for viewing
only, i have turned of allowing edits, adding, deleteing and column
reorg. when i click on the datagridview and go to edit columns and
select a column and look at the SortMode, it's set to automatic.
However, when i run the app and click on that column (with data in the
grid) it doesn't sort, it doesn't have the little markers on the column
header either. I understand that you can code behind to get the data
to sort, but I was thinking this was suppose to work as well. anyone
know what I'm not doing. seems if the sortmode is on automatic it
should sort them. The columns i'm talking about are textbox columns.
I have a bindingsource that was created when i drub a data source
object onto the form. the data source object was a object.

If I understand correctly you created the binding source using the data
source wizard "object" option, and you're now binding to a collection of
these objects. If you want sorting to work, it appears that one way is to
write your own custom collection deriving from BindingList<T> (where T is
the type of your object) and override the SupportsSearchingCore,
IsSortedCore, SortDirectionCore, SortPropertyCore properties and the
ApplySortCore and RemoveSortCore methods (plus various other methods if you
want to handle adding/removing items to the collection while it's sorted).
This is all described in detail in chapter 9 of "Data Binding with Windows
Forms 2.0" by Brian Noyes (publisher Addison Wesley), which I am currently
reading and highly recommend.

A slightly different approach is described in
http://www.msdn.net/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx.

Chris Jobson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top