I have a DataGridView with a few rows and I only want the ContextMenu to show when the user right-clicks a cell with data in it. I’ve used the MouseClick event to do this and then cmWhatever.Show() if the cell has data. All working fine, until I start to use a tablet, the right-click doesn’t work at all. I’m loathed to use a button in the grid and I guess I could hook into the “opening” event of the ContextMenu?
How can I get the tablet to show a menu on right-click of a valid cell in a DataGridView?
Yes the LongTap is the tablet and mobile equivalent of the right click. I think the library converts a long click (press the mouse and keep it pressed) to a long tap on desktops. You can always check the environment using Application.Browser.Device (https://wisej.com/docs/2.1/html/T_Wisej_Core_ClientBrowser.htm).
OK – I have worked around it using the LongTap event (not sure this is correct). I also saw recommendations to use CellMouseUp rather than MouseClick (saves checking the cell is a cell, not a header or the white-space). My code for showing the ContextMenu is:
private void grdTests_LongTap(object sender, EventArgs e)
{
Wisej.Web.DataGridView.HitTestInfo htInfo = grdTests.HitTest(grdTests.PointToClient(Cursor.Position).X, grdTests.PointToClient(Cursor.Position).Y);int iRow = htInfo.RowIndex;
int iCol = htInfo.ColumnIndex;if (iRow >= 0 && iCol >= 0) // has to be a cell, not a header or after the last row
{
string sTestID = grdTests[“RECORDID”, iRow].Value.ToString();cmTest.Tag = sTestID;
cmTest.Show(grdTests, grdTests.PointToClient(Cursor.Position), null);
}}
Please login first to submit.