PC Review


Reply
Thread Tools Rate Thread

DataGridView and sorting

 
 
ReneMarxis
Guest
Posts: n/a
 
      13th Nov 2007
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

 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      13th Nov 2007
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.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)


"ReneMarxis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
ReneMarxis
Guest
Posts: n/a
 
      13th Nov 2007
On 13 Nov., 17:02, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> 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.
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - m...@spam.guard.caspershouse.com
>


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.

 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      13th Nov 2007
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 Removed)

"ReneMarxis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 13 Nov., 17:02, "Nicholas Paldino [.NET/C# MVP]"
> <m...@spam.guard.caspershouse.com> wrote:
>> 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.
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - m...@spam.guard.caspershouse.com
>>

>
> 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.
>



 
Reply With Quote
 
ReneMarxis
Guest
Posts: n/a
 
      24th Nov 2007
On 13 Nov., 17:34, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> 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]
> - m...@spam.guard.caspershouse.com
>
> "ReneMarxis" <marxis.r...@googlemail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> > On 13 Nov., 17:02, "Nicholas Paldino [.NET/C# MVP]"
> > <m...@spam.guard.caspershouse.com> wrote:
> >> 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.

>
> >> --
> >> - Nicholas Paldino [.NET/C# MVP]
> >> - m...@spam.guard.caspershouse.com

>
> > 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting a datagridview vb.net 2008 msnews.microsoft.com Microsoft VB .NET 0 5th Sep 2009 07:36 PM
Sorting DataGridView Peter Morris Microsoft C# .NET 2 30th Sep 2007 11:12 AM
DataGridView--after sorting Kevin S Gallagher Microsoft Dot NET Framework Forms 9 20th Mar 2007 03:21 PM
Sorting a Datagridview amit.vasu@gmail.com Microsoft C# .NET 3 17th May 2006 02:29 PM
Wierd sorting in DataGridView =?Utf-8?B?d2pvdXN0cw==?= Microsoft Dot NET Framework Forms 0 21st Feb 2006 09:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:44 AM.