如何通过右键单击来选择数据网格视图行?
发布于 2009-06-02 12:38:52
使其行为类似于鼠标左键?例如:
private void dataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
dataGridView.CurrentCell = dataGridView[e.ColumnIndex, e.RowIndex];
}
}发布于 2008-10-06 06:19:19
// Clear all the previously selected rows
foreach (DataGridViewRow row in yourDataGridView.Rows)
{
row.Selected = false;
}
// Get the selected Row
DataGridView.HitTestInfo info = yourDataGridView.HitTest( e.X, e.Y );
// Set as selected
yourDataGridView.Rows[info.RowIndex].Selected = true;发布于 2008-10-16 10:07:15
最酷是在右击上添加一个菜单,例如,带有“查看客户信息”、“验证最后的发票”、“将日志条目添加到此客户”等选项。
您只需添加一个ContextMenuStrip对象,添加菜单项,并在DataGridView属性中选择它的ContextMenuStrip即可。
这将在用户右键单击的行中创建一个包含所有选项的新菜单,然后您所需做的就是变魔术:)
请记住,您需要JvR代码来获取用户所在的行,然后获取包含客户端ID的单元格并传递该信息。
希望它能帮助改进您的应用程序
http://img135.imageshack.us/img135/5246/picture1ku5.png
http://img72.imageshack.us/img72/6038/picture2lb8.png
https://stackoverflow.com/questions/173295
复制相似问题