怎么让 右键点击dataGridView可以选中
答案:2 悬赏:0 手机版
解决时间 2021-02-06 03:11
- 提问者网友:萌卜娃娃
- 2021-02-05 02:37
怎么让 右键点击dataGridView可以选中
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-02-05 03:36
[解决办法]
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
int x = this.dataGridView1.HitTest(e.X,e.Y).RowIndex;
int y = this.dataGridView1.HitTest(e.X,e.Y).ColumnIndex;
if (x != -1 && y != -1)
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[x].Cells[y];
}
}
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
int x = this.dataGridView1.HitTest(e.X,e.Y).RowIndex;
int y = this.dataGridView1.HitTest(e.X,e.Y).ColumnIndex;
if (x != -1 && y != -1)
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[x].Cells[y];
}
}
全部回答
- 1楼网友:末日狂欢
- 2021-02-05 05:11
///
/// 在datagridview控件的cellmousedown事件中实现
///
///
///
private void datagridview1_cellmousedown(object sender, datagridviewcellmouseeventargs e)
{
int rowindex = e.rowindex;
int columnindex = e.columnindex;
if (rowindex != -1 && columnindex != -1)
{
datagridview1.currentcell = datagridview1.rows[rowindex].cells[columnindex];
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯