We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Getting selected rows in right order

Hi,

I need to get all selected rows from a grid control in the right order. If I do a foreach loop through grid.Selections I get the ranges in wrong order. How do I get the selected rows in numerical order (e.g. 1,2,7,8,9 instead of 7,8,9,1,2 as I get it now) without sorting selected row indexes myself?

I'm using version 8.204.0.18.

Regards,
Christian


3 Replies

JJ Jisha Joy Syncfusion Team July 14, 2011 12:22 PM UTC

Hi Christian,

Thank you for using Syncfusion products.

You could get the currently selected rows by getting the selected ranges by using GetSelectedRows method and iterate through GridRangeInfoList.

See the code:


private void button1_Click(object sender, EventArgs e)
{
GridRangeInfoList rangeList = this.gridControl1.Selections.GetSelectedRows(true, false);
if (rangeList.Count > 0)
{
foreach (GridRangeInfo range in rangeList)
{

for (int row = range.Top; row <= range.Bottom; row++)
{
for (int col = 1; col <= gridControl1.ColCount; col++)
{
Console.Write( this.gridControl1[row, col].CellValue + " ");

}
Console.WriteLine();

}
}
}
}



Sample for your reference:

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GCSelections-1468458982.zip

Please let me know if you have any questions.

Regards,
Jisha





CR Christian Rattat July 14, 2011 06:39 PM UTC

Hi,

that's what I already tried but as mentioned in my original post, I get the selected rows not ordered but in arbitrary order. With your sample I need to put the row numbers first all in a temporary list, sort them and then I can iterate through the selected rows top down in the right order.

So what I need is a method that gives me the selected rows ordered by row number without having to sort them manually each time. Is there any method like this? It's quite annoying to first iterate through a couple thousand indexes, sort them each time just to iterate it again then in the right order.

Thanks and regards,
Christian



KB Kalaiarasan B Syncfusion Team July 19, 2011 02:02 PM UTC

Hi Christian,

Thank you for the update.

We are checking for other possibilities other than using a temporary list to sort the rows by row number,but also by optimizing the iteration to sort in the temp list, you can achieve it. We will update you with the solution shortly.

Appreciate your patience.

Regards,
Kalai.


Loader.
Live Chat Icon For mobile
Up arrow icon