简体   繁体   English

在datagridview中选择整行

[英]Selecting whole row in datagridview

I want to select whole row of DataGridView, when I click on some cell in it. 当我单击其中的某些单元格时,我想选择DataGridView的整行。

I added this code in CellMouseDown event 我在CellMouseDown事件中添加了此代码

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{   
    dataGridView1.Rows[e.RowIndex].Selected = true;
}


And it doesnt work, when I add this line to CellMouseClick event, it works, but it is slowly, it wait for mouse release, and then select it. 而且它不起作用,当我将此行添加到CellMouseClick事件时,它可以工作,但是速度很慢,它等待鼠标释放,然后选择它。

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].Selected = true;
}


Any solutions? 有什么办法吗?

There are property in GridView Related Of Mode Of Selecting Row in gridview GridView中有一些属性与gridview中选择行的模式有关

dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

You Can Reference To This Document https://msdn.microsoft.com/en-us/library/3c89df86(v=vs.110).aspx 您可以参考本文档https://msdn.microsoft.com/zh-cn/library/3c89df86(v=vs.110).aspx

Are you sure you select the option Full Row Select into the properties of the Datagrid like this: 确定要在Datagrid的属性中选择“ 全行选择 ”选项,如下所示:

全行选择

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM