Basic GridGroupingControl Question

using v5.

I'm not sure why this is so hard to figure out, but I simply have an add button and when clicked on, I want to retrieve the row in the grid that is currently selected.

Thanks,
Dan

3 Replies

SA Saravanan A Syncfusion Team June 5, 2007 09:34 PM UTC

Hi Dan,

You can get the selected ranges from the gridGroupingControl1.TableControl.Selections property. It return the GridRangeInfoList collection, which contains all the selected ranges.

Here is the code snippet to get the selected row index.

private void button1_Click(object sender, EventArgs e)
{
GridRangeInfoList rangeList;
if (this.gridGroupingControl1.TableControl.Selections.GetSelectedRanges(out rangeList, false))
{
foreach (GridRangeInfo range in rangeList)
{
if (range.RangeType == GridRangeInfoType.Rows)
{
for (int i = range.Top; i <= range.Bottom; i++)
{
Console.WriteLine("Row {0} is selected", i);
}
}
}
}
}


Best Regards,
Saravanan


DE Deian June 18, 2007 08:42 PM UTC

I have a GridGroupingControl.
There are in total 4 rows in the control - using your code I've got the following output:

Row 3 is selected
Row 4 is selected
Row 5 is selected
Row 6 is selected

Where is this coming from? Why is the selection has an offset?

Thank you in advance
Deian


SA Saravanan A Syncfusion Team June 18, 2007 10:33 PM UTC

Hi Dan,

Where is this coming from? Why is the selection has an offset?
>>>>>>>>>>>>>>>
The above code returns the RowIndex of the selected rows, with relative to the grid.
The grid will display each elements llike Caption, ColumnHeaders, FilterBar, AddNew row, ect., in different rows. Since these rows are displaying above the records, the rowindex of the records will get some offset and this offset will vary based on the number of elements displayed above the records.
You can find this offset using the gridGroupingControl1.TableControl.GetMinimumTopRowIndex() method. It returns the rowindex of the first record displayed in the grid.

If you are looking for the index of these selected rows in the binded datasource, please refer to the following KnowledgeBase article
How do I get the position of a row in the datasource from CurrentCell's rowIndex?

Best Regards,
Saravanan.

Loader.
Up arrow icon