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

Select rows when clicked on the group

I'd want to select all the sub-rows/grouped rows when the user clicks on the parent grid caption section. I wrote the following piece of code but the same does not work for me. Please suggest if i am missing something?

This is invoked on TableControlMouseDown event and I am using Grid grouping control version
4.4.0.51

if (e.Inner.Button == MouseButtons.Left)
{
int rowIndex, colIndex;
Point point = new Point(e.Inner.X, e.Inner.Y);
Boolean validRowCol = gridGroupingControl.TableControl.PointToRowCol(point, out rowIndex, out colIndex);
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(rowIndex, colIndex);
GridCaptionSection gridCaptionSection = style.TableCellIdentity.DisplayElement as GridCaptionSection;

if (gridCaptionSection != null)
{
foreach (Record rec in gridCaptionSection.ParentGroup.Records)
{
rec.SetSelected(true);
}
}
}


3 Replies

SR SubhaSheela R Syncfusion Team February 12, 2008 12:02 PM UTC

Hi John,

Thank you for using Syncfusion products.

You could get the DisplayElement in GridCaptionRow instead of GridCaptionSection, which is used to get rows of the group caption. Below is the code snippet:

if (e.Inner.MouseEventArgs.Button == MouseButtons.Left)
{
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
Element el = style.TableCellIdentity.DisplayElement;
GridCaptionRow gcr = style.TableCellIdentity.DisplayElement as GridCaptionRow;
if (gcr != null)
{
string s = "";
foreach (Record rec in gcr.GetCaptionSection().ParentGroup.Records)
{
s += "Id: " + rec.GetValue("id").ToString() + "Item: " + rec.GetValue("item").ToString() + " " + Environment.NewLine;
}
this.label1.Text = s.ToString();
}
}


Please refer to the sample available in the link below and let me know if it helps:

http://websamples.syncfusion.com/samples/Grid.Windows/F71736/main.htm

Regards,
Subhasheela R



JR John Ruiz February 13, 2008 02:00 AM UTC



>Hi John,

Thank you for using Syncfusion products.

You could get the DisplayElement in GridCaptionRow instead of GridCaptionSection, which is used to get rows of the group caption. Below is the code snippet:

if (e.Inner.MouseEventArgs.Button == MouseButtons.Left)
{
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
Element el = style.TableCellIdentity.DisplayElement;
GridCaptionRow gcr = style.TableCellIdentity.DisplayElement as GridCaptionRow;
if (gcr != null)
{
string s = "";
foreach (Record rec in gcr.GetCaptionSection().ParentGroup.Records)
{
s += "Id: " + rec.GetValue("id").ToString() + "Item: " + rec.GetValue("item").ToString() + " " + Environment.NewLine;
}
this.label1.Text = s.ToString();
}
}


Please refer to the sample available in the link below and let me know if it helps:

http://websamples.syncfusion.com/samples/Grid.Windows/F71736/main.htm

Regards,
Subhasheela R




I don't understand but the cast of displayeLement to type GridCaptionRow works fine when invoked in TableControlCellClick but not when implemented in TableControlMouseDown. Why is the displayElement different for different events.

For TableControlMouseDown i get the row and column index via the point which is calculated on gridGroupingControl.TableControl.PointToRowCol function. What is the current function to get the valid row, col index for a given point then?



JJ Jisha Joy Syncfusion Team February 14, 2008 06:50 AM UTC

Hi John,

If your intension is to select all the grouped rows when user click on the GridCaptionSection, this can be achieved by handling the TableControlCellClick event.

Please refer the following code snippets:

void gridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e)
{

Element el = this.gridGroupingControl1.Table.DisplayElements[e.Inner.RowIndex];
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex,e.Inner.ColIndex);
if (el.Kind == DisplayElementKind.Caption)
{
GridCaptionRow gcr = style.TableCellIdentity.DisplayElement as GridCaptionRow;
GridCaptionSection gcs = gcr.ParentSection as GridCaptionSection;
if (gcs != null)
{
foreach (Record rec in gcs.ParentGroup.Records)
{
rec.SetSelected(true);
}
}
}

}

Please refer the sample in the link to illustrate this:
http://websamples.syncfusion.com/samples/Grid.Windows/71736/main.htm

Kindly try this and let me know if you need further assistance.

Regards,
Jisha


Loader.
Live Chat Icon For mobile
Up arrow icon