trong sự kiện MouseDown của DataGirdview
PHP Code:
private void dtGview_MouseDown(object sender, MouseEventArgs e)
{
DataGridView.HitTestInfo hti;
if (e.Button == MouseButtons.Right)
{
hti = dtGview.HitTest(e.X, e.Y);
if (hti.Type == DataGridViewHitTestType.Cell)
{
if (!dtGview.Rows[hti.RowIndex].IsNewRow)
{
if (hti.Type == DataGridViewHitTestType.Cell && hti.RowIndex == hti.RowIndex)
{
contextMnStrip.Show(dtGview, new Point(e.X, e.Y));
}
dtGview.Rows[hti.RowIndex].Selected = true;
dtGview.CurrentCell = dtGview[hti.ColumnIndex, hti.RowIndex];
}
}
}
}
//dtGview là : tên DataGridview
trong sự kiên Form_Load bạn thêm cái này cho nó hiển thị ảnh và thực hiện phương thức sử lý khi Right Click
PHP Code:
Image img = global ::DataGridviewDemo.Properties.Resources.Exit;//đường dẫn File Ảnh
ContextMenuStrip contextMnStrip = new ContextMenuStrip();
contextMnStrip.Items.Add("In", img,new EventHandler(Print)); //Print : là Phương thức in hoặc sử lý ji đó mà bạn muốn