Right click is selecting old row.

Hi, I've got an issue with the GridGroupingControl. 

I use right click to display an context menu on a row.

Here is my issue : 

Left click on row 1 --> Right click on row 2 --> Display context menu for row 1 instead of row 2 

It selects the old selected value.

Here is my code :


private void gpcTaches_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
        {
            SelectedRecord rec = null;
            if (e.Inner.Button == MouseButtons.Right)
            {
                if (e.TableControl.Table.SelectedRecords.Count != 0)
                 rec = e.TableControl.Table.SelectedRecords[0];

                if (rec != null)
                    _idCmsTache = (int)rec.Record.GetValue("idTache");
            }
        }

Thanks

3 Replies

AR Arulpriya Ramalingam Syncfusion Team January 24, 2018 12:14 PM UTC

Hi Yoann,  
  
Thanks for contacting Syncfusion support.  
  
By default, the selected records will be added on both left and right click of the cells when and the selected records will be added to the collection after the mouse down completed. From your code part we suspect that you are trying to retrieve the current selected record on right click of the cell. In order to get the last selected record on right click of the cells, the TableControlCellClick event can be customized based on condition. In that event, the record can be retrieved by using the SelectedRecords collection based on index or CurrentRecord property. Please refer to the below code and sample,  
  
Code example  
  
//Event triggering  
this.gridGroupingControl1.TableControlCellClick += GridGroupingControl1_TableControlCellClick;  
  
object _idCmsTache;  
//Event customization  
private void GridGroupingControl1_TableControlCellClick(object sender,GridTableControlCellClickEventArgs e)  
{  
    if (e.Inner.MouseEventArgs.Button == MouseButtons.Right)  
    {  
        SelectedRecord rec = null;  
        if (e.Inner.MouseEventArgs.Button == MouseButtons.Right)  
        {  
            //Suggestion 1  
            //Using CurrentRecord propertys  
            Record record = e.TableControl.Table.CurrentRecord;  
            if (record != null)  
            {  
                _idCmsTache = rec.Record.GetValue("CategoryID");  
            }  
  
            //Suggestion 2  
            //Using SelectedRecords collection  
            int count = e.TableControl.Table.SelectedRecords.Count;  
            if ( count != 0)  
               rec = e.TableControl.Table.SelectedRecords[count - 1];  
            if (rec != null)  
            {  
                _idCmsTache = rec.Record.GetValue("CategoryID");  
            }  
        }  
    }  
}  
  
  
Note  
  
If you want to select the records only on mouse left click, SelectMouseButtonMask property can be set to Left 
  
//To disable the selecting records on mouse right click  
this.gridGroupingControl1.TableModel.Options.SelectCellsMouseButtonsMask =MouseButtons.Left;  
  
Regards,  
Arulpriya  



YG Yoann Gaborieau January 24, 2018 01:47 PM UTC

Works like a charm ! Thanks a lot !


AR Arulpriya Ramalingam Syncfusion Team January 25, 2018 04:04 AM UTC

Hi Yoann, 
 
Thanks for your update. 

We are glad to hear that the provided solution was resolved your scenario.   
 
Please let us know, if you have any other queries. 
 
Regards, 
Arulpriya 


Loader.
Up arrow icon