Add to selected items in MultiSelect drop down grid in GridControl

I have a working multi-select grid as an EmbeddedGrid acting as a drop-down in a GridControl cells. However, when I hold down the CTRL key and click in the grid in order to add to an existing set of selected rows, All the existing selections are cleared . How do I add to the selections in the grid when in the drop down?

3 Replies

DY Deivaselvan Y Syncfusion Team October 1, 2018 10:29 AM UTC

Hi Robert,

Thank you for contacting Syncfusion support.

By default, GridControl selection has cleared when you click on the unselected drop-down button in MultiExtended selection mode. To avoid these selections are cleared when click on the drop down button, you could handle the SelectionChanging, CellButtonClicked and KeyDown event. Please refer the following code example and the sample,

Code example

 
this.gridControl1.SelectionChanging += GridControl1_SelectionChanging; 
this.gridControl1.CellButtonClicked += GridControl1_CellButtonClicked; 
//To identify the control key is pressed or not. 
this.gridControl1.KeyDown += GridControl1_KeyDown; 
 
bool isDropDownButtonClicked = false; 
bool isControlPressed = false; 
 
 
private void GridControl1_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (e.KeyData == (Keys.ControlKey | Keys.Control)) 
    { 
        isControlPressed = true; 
    } 
} 
 
private void GridControl1_CellButtonClicked(object sender, GridCellButtonClickedEventArgs e) 
{ 
    if (e.ColIndex == 5 && isControlPressed) 
    { 
        isDropDownButtonClicked = true; 
        //To select the row 
        this.gridControl1.Selections.Add(GridRangeInfo.Row(e.RowIndex)); 
        isControlPressed = false; 
    } 
} 
 
private void GridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e) 
{ 
    GridCurrentCell currentCell = this.gridControl1.CurrentCell; 
    if (currentCell.ColIndex == 5 && isDropDownButtonClicked) 
     { 
        e.Cancel = true; 
        isDropDownButtonClicked = false; 
     } 
} 

Sample link:
http://www.syncfusion.com/downloads/support/directtrac/general/ze/cs124964705

Please let us know if we misunderstood your scenario.

Regards,
Deivaselvan 



RD Robert Dickow October 7, 2018 08:18 AM UTC

Thanks very much for the tip. My solution is a little different but your code, but it put me on the right track to get things working well.



AA Arulraj A Syncfusion Team October 8, 2018 08:58 AM UTC

Hi Robert, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Arulraj A 


Loader.
Up arrow icon