This is a migrated thread and some comments may be shown as answers.

Get row indexes of selected cells from filtered rows.

2 Answers 301 Views
GridView
This is a migrated thread and some comments may be shown as answers.
özer
Top achievements
Rank 2
Veteran
Iron
özer asked on 31 Dec 2020, 02:11 PM

Hi.
I have a RadGridView that SelectionMode property is set to CellSelect.

Dictionary<int, string> drms = new Dictionary<int, string>();
 
private void ddlSetDurum_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            if (ddlSetDurum.SelectedIndex != 0)
            {
                drms.Clear();
 
                foreach (var item in rgvTakip.SelectedCells)
                {
                    int i = item.RowInfo.Index; // Works fine if no column filtering is done
                    if (!drms.ContainsKey(i))
                    {
                        drms.Add(i, rgvTakip.Rows[i].Cells["tkd"].Value.ToString());
                        rgvTakip.Rows[i].Cells["tkd"].Value = ddlSetDurum.SelectedText; 
                    }
                }
                isDurumSet = true;
                ddlSetDurum.SelectedIndex = 0;
            }
        }

 

After filtering by any column, when I try to get the row index of the selected cells, it gives me the index number in the rows created after the filtering process.

When I want to change the value of a cell using the obtained row index, this time it works according to the original table, not the filtered table.

So I have to get the original index number of that cell before filtering.

2 Answers, 1 is accepted

Sort by
0
özer
Top achievements
Rank 2
Veteran
Iron
answered on 02 Jan 2021, 08:53 PM
I found the solution. It was very simple, the childRows property gives the indexes I want.
0
Nadya | Tech Support Engineer
Telerik team
answered on 04 Jan 2021, 08:13 AM

Hello, özer,

I am glad that you managed to find a solution that works for you. If you want to access the rows after filtering using the ChildRows collection is the right approach. The ChildRows collection is modified every time a data operation (grouping, sorting, filtering) occurs. More information is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/rows-vs-childrows#rows-vs-childrows 

Should you have any other questions do not hesitate to ask.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
özer
Top achievements
Rank 2
Veteran
Iron
Answers by
özer
Top achievements
Rank 2
Veteran
Iron
Nadya | Tech Support Engineer
Telerik team
Share this question
or