当用户单击该行的单元格时,如何选择完整的 dataGridView 行? [英] How do I select a complete dataGridView Row when the user clicks a cell of that row?

查看:16
本文介绍了当用户单击该行的单元格时,如何选择完整的 dataGridView 行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 dataGridView 并且我需要它,当用户点击任何单元格时,包含该单元格的整行也被选中.(它已取消多选)我尝试像这样获取 currentRowIndex

I have a dataGridView and I need that when the user clicks on any cell the whole row that contains this cell is selected too. (it has multiselect disbaled) I tried getting the currentRowIndex like this

 int Index = dataGridView1.CurrentCell.RowIndex;

但是,我不确定如何使用索引来选择该行.尝试了这个和其他六种方法但没有成功:

However, I am not sure how to use the index in order to select that row. Tried this and about other six ways with no success:

dataGridView1.Select(Index);

你知道我可以这样做的方法吗?

Do you know a way I can do this?

推荐答案

需要将datagridview的SelectionMode设置为FullRowMode.

You need to set datagridview's SelectionMode to FullRowMode.

注意:在带有 .NET 4.5 的 Visual Studio 2013 中,该属性称为 FullRowSelect.

Note: In Visual Studio 2013 with .NET 4.5 the property is called FullRowSelect.

这篇关于当用户单击该行的单元格时,如何选择完整的 dataGridView 行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆