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
close icon

GridDataBoundGrid and multiple selection

Hi, we have a GridDataBoundGrid in which we would like to be able to do the following :

1. User selects multiple rows.

2. User changes value of one of the cells.

3. Cell's new value is copied to all other cells in that column for the selected rows.

However, the problem we are seeing is in step 2 - when the user left-clicks into a textbox cell to change the value the multiple row selection is cleared and only that cell's row is selected. However, if the column is a combobox with dropdowns, then the new value can be selected without clearing the old row selections.

In this GDBG the ListBoxSelectionMode is set to MultiExtended. The grid.Model.Options.SelectCellsMouseButtonsMask is also set to MouseButtons.Left so as to enable context menu for multiple row selections.

We've tried GridModelOptions.ExcelLikeCurrentCell and MulitExtendedArrowKeySelect, but these don't seem to help. Is there any way to make this idea work ? Thanks for any assistance !

-Rob

2 Replies

AD Administrator Syncfusion Team March 23, 2007 10:49 PM UTC

Hi Rob,

This can be achieved by handling the Model.SelectionChanging event for keeping the existing selected ranges when pressing left mouse click and CurrentCellCahnged event for coping the current cell text to all selected cells in a grid. Please refer this sample and let me know if this helps.

void Model_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
if (e.Reason == GridSelectionReason.MouseDown)
{
GridModel model = sender as GridModel;
GridRangeInfoList list = model.SelectedRanges;
foreach (GridRangeInfo range in list)
{
if (range.IntersectsWith(e.ClickRange))
e.Cancel = true;
}
}
}

void gridDataBoundGrid1_CurrentCellChanged(object sender, EventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridRangeInfoList list = grid.Model.SelectedRanges;

object objEditState = grid.CurrentCell.Renderer.GetEditState();
foreach (GridRangeInfo range in list)
{
for (int i = range.Top; i <= range.Bottom; i++)
{
for (int j = range.Left; j <= range.Right; j++)
{
grid.Model[i, j].CellValue = grid.CurrentCell.Renderer.ControlValue;
}
}
}
grid.CurrentCell.BeginEdit();
grid.CurrentCell.Renderer.SetEditState(objEditState);
}

Best regards,
Haneef


RY Rob Yang March 24, 2007 02:47 PM UTC

Thanks, that worked !
-Rob

--
>Hi Rob,

This can be achieved by handling the Model.SelectionChanging event for keeping the existing selected ranges when pressing left mouse click and CurrentCellCahnged event for coping the current cell text to all selected cells in a grid. Please refer this sample and let me know if this helps.

void Model_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
if (e.Reason == GridSelectionReason.MouseDown)
{
GridModel model = sender as GridModel;
GridRangeInfoList list = model.SelectedRanges;
foreach (GridRangeInfo range in list)
{
if (range.IntersectsWith(e.ClickRange))
e.Cancel = true;
}
}
}

void gridDataBoundGrid1_CurrentCellChanged(object sender, EventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridRangeInfoList list = grid.Model.SelectedRanges;

object objEditState = grid.CurrentCell.Renderer.GetEditState();
foreach (GridRangeInfo range in list)
{
for (int i = range.Top; i <= range.Bottom; i++)
{
for (int j = range.Left; j <= range.Right; j++)
{
grid.Model[i, j].CellValue = grid.CurrentCell.Renderer.ControlValue;
}
}
}
grid.CurrentCell.BeginEdit();
grid.CurrentCell.Renderer.SetEditState(objEditState);
}

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon