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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Get SelectedCells order from top left to bottom right

Thread ID:

Created:

Updated:

Platform:

Replies:

128728 Feb 8,2017 08:19 AM UTC Feb 11,2017 04:06 AM UTC UWP 3
loading
Tags: SfDataGrid
Thomas Klocker
Asked On February 8, 2017 08:19 AM UTC

Hi @all!

I have a SfDataGrid with SelectionUnit set to Any and SelectionMode set to Multiple. Now the user can select some cells and can tap on a button and i will handle the selected cells.
But when i call GetSelectedCells on the SfDataGrid, i will get the cells in the order how they was selected, but i need to get the selected cells from the first cell to the last cell.

For example: user selects the cell B3 first, dann B2, then B1, then A3 and lastly A2. No when i call the GetSelectedCells function, i will get the Items B3, B2, B1, A3 And A2.
But i need to get the items like: A2, A3, B1, B2 and B3. (A2 and A3 are the first row in the grid, and B1/2/3 are the second row in the grid).

How can this be achieved?

Thanks for any help
Greetings

Thomas

Jai Ganesh S [Syncfusion]
Replied On February 9, 2017 04:50 PM UTC

Hi Thomas, 
 
You can achieve your requirement to get the selected cells always based on the minimum row index by using the below code, 
 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    List<int> rowIndex = new List<int>(); 
    List<GridCellInfo> listOfCells = new List<GridCellInfo>(); 
    var cells = this.sfGrid.GetSelectedCells(); 
 
    //Get the row index based on the selected cells and sorted it 
    foreach(var item in cells) 
    { 
        var rindex = this.sfGrid.ResolveToRowIndex((item as GridCellInfo).RowData); 
        rowIndex.Add(rindex); 
    } 
    rowIndex.Sort(); 
 
    //Get the Selected cells based on the sorted row index  
    for (int j=0;j<rowIndex.Count;j++) 
    { 
        foreach (var item in cells) 
        { 
            var rindex = this.sfGrid.ResolveToRowIndex((item as GridCellInfo).RowData); 
 
        if (rindex == rowIndex[j]) 
            listOfCells.Add(item); 
        } 
 
    } 
} 
 
 
Regards, 
Jai Ganesh S 
 


Thomas Klocker
Replied On February 10, 2017 12:59 PM UTC

Hi Jai,

very much thanks. works great!

Greetings
Thomas


Jai Ganesh S [Syncfusion]
Replied On February 11, 2017 04:06 AM UTC

Hi Thomas, 
Thank you for the update. 
Please let us know if you need further assistance on this. 
Regards, 
Jai Ganesh S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;