Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

DataGridView and sorting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ReneMarxis - 13 Nov 2007 15:20 GMT
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
Nicholas Paldino [.NET/C# MVP] - 13 Nov 2007 16:02 GMT
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.

Signature

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

> Hello
>
[quoted text clipped - 10 lines]
>
> _tia rene
ReneMarxis - 13 Nov 2007 16:22 GMT
On 13 Nov., 17:02, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> Rene,
>
[quoted text clipped - 5 lines]
>           - 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.
Nicholas Paldino [.NET/C# MVP] - 13 Nov 2007 16:34 GMT
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.

Signature

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

> On 13 Nov., 17:02, "Nicholas Paldino [.NET/C# MVP]"
> <m...@spam.guard.caspershouse.com> wrote:
[quoted text clipped - 20 lines]
> I mean that should be a very popular situation and i can't imagin its
> not allready inside.
ReneMarxis - 24 Nov 2007 15:57 GMT
On 13 Nov., 17:34, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> Rene,
>
[quoted text clipped - 31 lines]
> > 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.