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

Auto-selection of grouped rows

Hi,

In this sample application I want to select/deselect all rows underneath a specific group when any of the rows underneath that group is clicked. This is not working well in the sample code however. Please could you help out with this?

Many Thanks

RowSelectionTest.zip

10 Replies

HA haneefm Syncfusion Team May 31, 2007 03:42 PM UTC

Hi Ys,

You can do this by handling the TableControlCellClick event and select the all group record using the record.SetSelected method. Here is a code snippet

void mainGridGroupingControl_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e)
{
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex);
if (style != null)
{
Record rec = style.TableCellIdentity.DisplayElement.GetRecord();
if (rec != null)
{
foreach (Record r in rec.ParentGroup.Records)
{
r.SetSelected(true);
}
}
}
}

Also refer the below KB article that shows you "How to select a group of rows in a grid?".
http://www.syncfusion.com/support/Forums/message.aspx?&MessageID=58319

Best regards,
Haneef


YS Yong Shen Foo June 1, 2007 05:04 PM UTC

Hi Haneef,

I would also need to un-select all rows underneath a parent group when any row within it is CTRL-clicked. At the moment it un-selects only the row which was CTRL-clicked. What would be the best way to go about this?


HA haneefm Syncfusion Team June 1, 2007 07:46 PM UTC

Hi Ys,

In your TableControlCellClick event, if Control.ModifierKeys is equals to Keys.Control, then try calling the SelectedRecords.Clear method to clear previous selected records in a table and set current record as selected by calling CurrentRecord.SetSelected method. Here is a code snippet

///TableControlCellClick
if( Control.ModifierKeys == Keys.Control )
{
e.TableControl.Table.SelectedRecords.Clear(); //Clear all records
e.TableControl.Table.CurrentRecord.SetSelected(true); //Selected current record
}

Best regards,
Haneef


YS Yong Shen Foo June 2, 2007 02:59 PM UTC

Hi Haneef,

Unfortunately the TableControlCellClick event only catches the control modifier key press when a row is selected but not when it's de-selected, hence the above solution does not work.


HA haneefm Syncfusion Team June 4, 2007 11:54 PM UTC

Hi Ys,

Please try the attached sample and let me know if this helps.
http://websamples.syncfusion.com/samples/Grid.Windows/F61830/main.htm

Best regards,
Haneef


YS Yong Shen Foo June 5, 2007 10:05 AM UTC

Hi Haneef,

Unfortunately it does not work the way I need it to. Clicking any row under the parent selects all its rows - this is fine. However, once all rows underneath a parent are selected, ctrl-clicking any of those selected rows should de-select all children rows as well - the sample code does not do that and TableControlCellClick does not handle the control modifier key when de-selecting a row.


HA haneefm Syncfusion Team June 5, 2007 11:04 PM UTC

Hi Ys,

Here is a modified sample that talk about this event.
http://websamples.syncfusion.com/samples/Grid.Windows/F61830(2)/main.htm

Best regards,
Haneef


YS Yong Shen Foo June 6, 2007 11:13 AM UTC

Hi Haneef,

Unfortunately this does not work with

TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended;

Ultimately I need to be able to Ctrl+ select/de-select multiple rows from different groups. When a row in a particular group is selected/de-selected with or without the Ctrl modifier, all rows in that group need to be selected/de-selected accordingly; thus that entire parent group behaves like a single row in a SelectionMode.MultiExtended environment.
Thanks for looking into this.




HA haneefm Syncfusion Team June 6, 2007 08:49 PM UTC

Hi Ys,

You will need to handle the two grid events( TableContolMouseDown and SelectedRecordChanging event). one for selecting/de-selecting the multiple records in a group when it is clicked. The SelectedRecordChanging event used for disable the record selection technique in a grid. The attached sample implements two events to answer this. Please try the attached sample and let me know if this helps.

void gridGroupingControl1_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
{
Element el = e.TableControl.PointToNestedDisplayElement(new Point(e.Inner.X, e.Inner.Y));
Record rec = el.GetRecord();
if (rec != null)
{
AllowSelectGroup = true;
bool isSelected = Control.ModifierKeys != Keys.Control? true:!rec.IsSelected();
if( Control.ModifierKeys != Keys.Control )
e.TableControl.Table.SelectedRecords.Clear();
foreach (Record r in rec.ParentGroup.Records)
r.SetSelected(isSelected);
AllowSelectGroup = false;
}
}
bool AllowSelectGroup = false;
void gridGroupingControl1_SelectedRecordsChanging(object sender, SelectedRecordsChangedEventArgs e)
{
if( !AllowSelectGroup )
e.Cancel = true;
}

Sample : GGCSelectRecord.zip

Best regards,
Haneef


YS Yong Shen Foo June 7, 2007 02:39 PM UTC

Hi Haneef,

With a few modifications, this now functions as expected . Many thanks for your assistance.

Loader.
Live Chat Icon For mobile
Up arrow icon