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.
Unfortunately, activation email could not send to your email. Please try again.

Auto-selection of grouped rows

Thread ID:

Created:

Updated:

Platform:

Replies:

61711 May 31,2007 06:43 AM Jun 7,2007 10:39 AM Windows Forms 10
loading
Tags: Grouping
Yong Shen Foo
Asked On May 31, 2007 06:43 AM

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

haneefm [Syncfusion]
Replied On May 31, 2007 11:42 AM

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

Yong Shen Foo
Replied On June 1, 2007 01:04 PM

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?

haneefm [Syncfusion]
Replied On June 1, 2007 03:46 PM

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

Yong Shen Foo
Replied On June 2, 2007 10:59 AM

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.

haneefm [Syncfusion]
Replied On June 4, 2007 07:54 PM

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

Yong Shen Foo
Replied On June 5, 2007 06:05 AM

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.

haneefm [Syncfusion]
Replied On June 5, 2007 07:04 PM

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

Yong Shen Foo
Replied On June 6, 2007 07:13 AM

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.



haneefm [Syncfusion]
Replied On June 6, 2007 04:49 PM

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

Yong Shen Foo
Replied On June 7, 2007 10:39 AM

Hi Haneef,

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

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.

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.

;