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

Selecting records in GCC

hi,

I have a requirement like this.

A user can select a single record by left clicking on that record’s row header, or can alternatively select multiple records by using CTRL+Click and/or SHIFT+Click.

I want to de some further processing on the selected records. So i should be able to capture the selected records

I am using Grid Grouping control.

Can you share some sample to achieve this.

5 Replies

AD Administrator Syncfusion Team March 20, 2007 04:36 PM UTC

Hi Dinesh,

You can set the TableOptions.AllowSelection property to GridSelectionFlags.Any; in a grid and use TableModel.Selections property to manage the selection like get the selected row, add the selection,etc in a grid. Please find the code snippet below.

//Enable the cell based selection tech
this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Any;

//Button click event
GridTableModel model = this.gridGroupingControl1.TableModel as GridTableModel;
foreach(GridRangeInfo info in model.Selections.GetSelectedRows(true,true))
{
for(int i = info.Top ; i<= info.Bottom ;i++)
{
//To get the selected records.
// and invalid the record here....
if( model.Table.DisplayElements[i].Kind == DisplayElementKind.Record)
Console.WriteLine(i +":::" + model.Table.DisplayElements[i].ParentRecord);
}
}

For more details about selection types, See
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=344

Regards,
Haneef


DU dinesh upreti March 26, 2007 01:28 PM UTC

hi,

The sample and code that u shared looks a little close to my requirements.

I also added the following snippent to the code as i wanted that selection should not get lost till user clicks outside the range.

private void TableModel_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
Console.WriteLine("SelectionChanging:"+" Range"+e.Range.ToString());
if (e.Reason == GridSelectionReason.MouseDown)
{
GridTableModel model = sender as GridTableModel;
GridRangeInfoList list = model.SelectedRanges;
foreach (GridRangeInfo range in list)
{
if (range.IntersectsWith(e.ClickRange))
e.Cancel = true;
}
// Console.WriteLine("Count:" + " --- " + model.Table.Records.Count.ToString());
}
//
}


The problem is that as i am trying to simulate an excel like functionality, when user right clicks the grid after selecting a range, the selection should not be lost and a context menu should pop up which is applicable to selected range.

however, as happens in excel, if user left clicks on a selected range, the range selection should be cleared. Can you share some code to be able to achieve that


>Hi Dinesh,

You can set the TableOptions.AllowSelection property to GridSelectionFlags.Any; in a grid and use TableModel.Selections property to manage the selection like get the selected row, add the selection,etc in a grid. Please find the code snippet below.

//Enable the cell based selection tech
this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Any;

//Button click event
GridTableModel model = this.gridGroupingControl1.TableModel as GridTableModel;
foreach(GridRangeInfo info in model.Selections.GetSelectedRows(true,true))
{
for(int i = info.Top ; i<= info.Bottom ;i++)
{
//To get the selected records.
// and invalid the record here....
if( model.Table.DisplayElements[i].Kind == DisplayElementKind.Record)
Console.WriteLine(i +":::" + model.Table.DisplayElements[i].ParentRecord);
}
}

For more details about selection types, See
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=344

Regards,
Haneef


RA Rajagopal Syncfusion Team March 27, 2007 12:23 AM UTC

Hi Dinesh,

Please use the below property setting to prevent right click from affecting any selections. This will help you.

this.gridGroupingControl1.TableModel.Options.SelectCellsMouseButtonsMask = MouseButtons.Left;

Regards,
Rajagopal


DU dinesh upreti March 27, 2007 12:43 PM UTC

Thanks.

Can you also tell me how to programatically clear any range or cell selections made in a grid, say on the click of a button.

Thanks

Dinesh Upreti

>Hi Dinesh,

Please use the below property setting to prevent right click from affecting any selections. This will help you.

this.gridGroupingControl1.TableModel.Options.SelectCellsMouseButtonsMask = MouseButtons.Left;

Regards,
Rajagopal


JS Jeba S Syncfusion Team March 27, 2007 01:02 PM UTC

Hi Dinesh,

To clear any selections, please try this code snippet:

this.gridGroupingControl1.TableControl.Selections.Clear()
this.gridGroupingControl1.TableControl.SelectRecords.Clear()


Kindly let us know if this helps.

Best Regards,
Jeba.

Loader.
Live Chat Icon For mobile
Up arrow icon