Support Forums

Full Version: datagridview help needed!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I have a form (form1) with a datagridview (datagridview1) which contains 8 columns (member#, mound#, name, age, range fee, gun hire, total, score), yes this is for a gun club.

I am having two problems when sorting the data (clicking on the column title),
firstly, when I try and sort a column which contains Integers only (score for example), when this order is sorted, this is how it is displayed :

1
100
150
25
30
300

Now obviously this isn't how I would like my data to be sorted, I want it in a logical way :

1
25
30
100
150
300

How would I go about changing the way in which the data is sorted? (this data is not bound to a database)

secondly, when I want the data to be sorted between two columns (age and score) this is what I get: (note J is junior and S is senior)

age - score
J - 100
J - 25
J - 150
S - 300
S - 1
S - 30

It is sorting the data by age, the the score column is being sorted in the order the row was added to the database, this is how I would like the data to be displayed :

age - score
J - 25
J - 100
J - 150
S - 1
S - 30
S - 300

Could anyone please explain how I could make the datagridview sort as shown above?

Many thanksSmile

(data is hypothetical)
I have been searching about that for almost an hour, but I couldn't find anything. It's strange that Microsoft hasn't thought about it. Perhaps you could make your own sort function though, and replace the normal one. (It won't be easy).
I've been looking into this for two weeks now.

So far I have found :

A modified dgv dll which enables the columns to be multi-sorted (although I haven't figure out how to manipulate the sorting method so it works for numerics)

A source code for when you click a button, it programmatically multi-sorts two specified columns, using iComparer (same as above, haven't found a way to sort for numerics using this method)

I have got a code set up for sorting numeric values. This works by changing the SortOrder event, this event isn't called for the numberic column in the other two methods.

It seems the best way to go is by using the dll, I just need to figure out how to use the sorting method when using this.