473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataGridView and sorting

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

Nov 13 '07 #1
4 4774
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]
- mv*@spam.guard.caspershouse.com
"ReneMarxis" <ma*********@googlemail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
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

Nov 13 '07 #2
On 13 Nov., 17:02, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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.

Nov 13 '07 #3
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]
- mv*@spam.guard.caspershouse.com

"ReneMarxis" <ma*********@googlemail.comwrote in message
news:11**********************@v2g2000hsf.googlegro ups.com...
On 13 Nov., 17:02, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>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.

Nov 13 '07 #4
On 13 Nov., 17:34, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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.comwrote in message

news:11**********************@v2g2000hsf.googlegro ups.com...
On 13 Nov., 17:02, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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
Nov 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: rob | last post by:
I have a class that among others exposes a string property "Date". The date in this property is stored in the form yyyymmdd. Now I do the following 1) Generate a DataGridViewTextBoxColumn column...
1
by: cc | last post by:
Hi, using the DataGridView (.NET 2005) : I have a row currently selected in the Grid (say the 3rd row showing 'Product3') Now, when I click on a column to sort the records is the 'Product3'...
4
by: Chris Botha | last post by:
VS2005 and I have a DataTable displayed in a DataGridView that needs custom sorting, with the DataSource of the grid set to the DataTable and the SortCompare event just won't fire. Then I found...
4
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone...
0
by: mahesh.nimbalkar | last post by:
I want to use Multi column sorting in DataGridView. The scenario is like this: 1) DataGridView has two columns; Id and name 2) User clicks on Id column and DataGridView is sorted...
1
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using a DataGridView on a Form. I want to disable the clicking on the columns headers to disallow the sorting. How can I do that, but without deriving the DataGridView? Is there any other...
8
by: Kyote | last post by:
On my form I have a datagridview that's bound to a table on my DB. When I run the app then click on a column header to sort, it sorts just fine. But my problem is a result of that sort. Even...
7
Plater
by: Plater | last post by:
I am having trouble determining when my DataGridView object is sorting (based on a column header click). The idea is, in a large table, sorting the columns takes time, so I show a splash screen....
0
by: Queez | last post by:
OK, this is rediculous... Surely, sorting should be one of the easiest things with the ASP.NET DataGridView control. I mean, there's hundreds of sites out there (Microsoft MSDN entries included)...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.