right click in c#

  • Thread starter Thread starter DBC User
  • Start date Start date
D

DBC User

Hi All,

I have a data grid and I created a context menu for the data grid and
is working fine. The context menu is sensitive to the current selected
row.
I would like to know., when a user RIGHT click on a particular row, I
want to select the row and then show the context menu (like outlook).
Could someone give me some pointers on this. I did some experiments but
none worked so far.

Thanks.
 
This works for me...

private void MyDataGridView_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right) return;
DataGridView.HitTestInfo Hti = MyDataGridView.HitTest(e.X, e.Y);
if (Hti.Type == DataGridViewHitTestType.Cell)
{
if (MyDataGridView.Rows.Count > 0)
{
MyDataGridView.CurrentCell = MyDataGridView[Hti.ColumnIndex,
Hti.RowIndex];

ShowContextMenu(this.PointToScreen(MyDataGridView.PointToClient(e.Location))
);
}//EndIf
}//EndIf
}//EndEvh MyDataGridView_MouseUp


Hope this helps,

Steph.
 
TheSteph said:
This works for me...

private void MyDataGridView_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right) return;
DataGridView.HitTestInfo Hti = MyDataGridView.HitTest(e.X, e.Y);
if (Hti.Type == DataGridViewHitTestType.Cell)
{
if (MyDataGridView.Rows.Count > 0)
{
MyDataGridView.CurrentCell = MyDataGridView[Hti.ColumnIndex,
Hti.RowIndex];

ShowContextMenu(this.PointToScreen(MyDataGridView.PointToClient(e.Location))
);
}//EndIf
}//EndIf
}//EndEvh MyDataGridView_MouseUp


Hope this helps,

Steph.




DBC User said:
Hi All,

I have a data grid and I created a context menu for the data grid and
is working fine. The context menu is sensitive to the current selected
row.
I would like to know., when a user RIGHT click on a particular row, I
want to select the row and then show the context menu (like outlook).
Could someone give me some pointers on this. I did some experiments but
none worked so far.

Thanks.

Thanks and it worked. Thats what I was looking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top