DataGridView and sorting

R

ReneMarxis

Hello

i have one problem with sorting in an unbound DataGridView. I set
sorting to automatic but i get errors when having DBNull values in the
column that gets sort ("Object must be of type string").
I solved that problem for one grid/column by fetching the _SortCompare
event and doing the sort manualy by seting the SortResult accordingly
if its a null value (-1) or not (e.Handled=false;return;)

Is there some possibility to specify that null values should alvays be
traded as "<"? I don t like to implement this event for every grid i
have in my project.

_tia rene
 
N

Nicholas Paldino [.NET/C# MVP]

Rene,

You could always derive a class from the DataGridView class which will
have the logic embedded in it, and then use that where you use your grids.
In this case, you would override the OnSortCompare method.
 
R

ReneMarxis

Rene,

You could always derive a class from the DataGridView class which will
have the logic embedded in it, and then use that where you use your grids.
In this case, you would override the OnSortCompare method.

Hello Nicholas

thanks for your answer.
I know i can do that :) but i would need to replace all existing grids
then.

My question was if there is some allready implemented feature that i
just wasn't able to find.
I mean that should be a very popular situation and i can't imagin its
not allready inside.
 
N

Nicholas Paldino [.NET/C# MVP]

Rene,

Are you triggering the sort through a call in code? If so, you can
create your own version of IComparer and pass that to the Sort method.

If not, then hooking to the event is really the only option you have.
 
R

ReneMarxis

Rene,

Are you triggering the sort through a call in code? If so, you can
create your own version of IComparer and pass that to the Sort method.

If not, then hooking to the event is really the only option you have.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Hello Nicholas
thanks for your answer.
I know i can do that :) but i would need to replace all existing grids
then.
My question was if there is some allready implemented feature that i
just wasn't able to find.
I mean that should be a very popular situation and i can't imagin its
not allready inside.

No. the sorting is triggered by clicking on the headers
 

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