您的位置:首页 > 编程语言 > C#

c# winform DataGridView选择一整行的相关属性

2016-11-19 15:42 218 查看
1.  设置DataGridView的属性SelectionMode为FullRowSelect 

     这样就使DataGridView不是选择一个字段,而是选择一整行了 

2.  设置DataGridView的属性MultiSelect为false 

     这样就使DataGridView不能够选择多行,只能选择一行了

3.  想得到某列的值是要判断DataGridView是否有选中的行

     if (dataGridView1.SelectedCells.Count != 0)

            {

                //得到选中行的索引

                int intRow = dataGridView1.SelectedCells[0].RowIndex;

                 //得到列的索引

                int intColumn = dataGridView1.SelectedCells[0].ColumnIndex;

                 //得到选中行某列的值

                string str = dataGridView1.CurrentRow.Cells[2].Value.ToString();

                MessageBox.Show(str);

            }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐