473,395 Members | 1,677 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,395 software developers and data experts.

datagrid sorting hassles

Hi all,
I've got a datagrid.
I have a function which selects certain rows in a datagrid thus:

public void selectRows(string key, string columnName)
{
int count = 0;
foreach(DataRow dr in ((DataView)dg_aspects.DataSource).Table.Rows)
{
if(dr[columnName].ToString()==key)
dg_aspects.Select(count);
else
dg_aspects.UnSelect(count);
count++;
}
}

This works, but when the user clicks a column header to sort the
datagrid, the selected columns remain at the same index.

For example - if the top two rows are selected initially.
After sort - the top two rows are still selected, but the datagrid is
showing different results in those rows.

It appears that the DataTable the DataGrid is showing, and the
DataDource we work with aren't the same where sorting is concerned.

Does anyone know how to get a handle on the sorted DataTable?

I hope that's clear - thanks for taking a look
Steven
Nov 16 '05 #1
1 1345
Hi Steven,

I see your problem - but the grid cannot do this for you. A workaround can
be to remember the selected rows' primary keys and when the grid is
re-sorted, unselect any selected rows and re-select the rows having the
remembered primary keys.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"steven shingler" <st*************@virgin.net> wrote in message
news:95**************************@posting.google.c om...
Hi all,
I've got a datagrid.
I have a function which selects certain rows in a datagrid thus:

public void selectRows(string key, string columnName)
{
int count = 0;
foreach(DataRow dr in ((DataView)dg_aspects.DataSource).Table.Rows)
{
if(dr[columnName].ToString()==key)
dg_aspects.Select(count);
else
dg_aspects.UnSelect(count);
count++;
}
}

This works, but when the user clicks a column header to sort the
datagrid, the selected columns remain at the same index.

For example - if the top two rows are selected initially.
After sort - the top two rows are still selected, but the datagrid is
showing different results in those rows.

It appears that the DataTable the DataGrid is showing, and the
DataDource we work with aren't the same where sorting is concerned.

Does anyone know how to get a handle on the sorted DataTable?

I hope that's clear - thanks for taking a look
Steven


Nov 16 '05 #2

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

Similar topics

0
by: Chris Mayers | last post by:
I have a Windows Forms DataGrid that has a DataView as a datasource. My problem is that I want the datagrid to exhibit some special sorting properties when the header rows are clicked on. From...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
1
by: Sargas Atum | last post by:
Hi all, 1. I have a problem with cell selection in a table in a DataGrid. I dont want that anybody writes in the cells. That was not a problem I changed them to "read only", but if I am going...
3
by: melanieab | last post by:
Hi, I'm programatically sorting in a datagrid. When a column header is clicked, the sort happens twice for some reason, making it looks like it only sorts in descending order. I can tell it...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
4
by: Manny Chohan | last post by:
hi guys, my code is returning an array and i need to create datagrid so that i can have sorting and implement prev....next function on it to navigate. is there any way this can be done in...
5
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
1
by: ECD | last post by:
Hello all, I can usually find solutions to my .NET problems by searching these groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0 framework). I want to disable sorting on...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.