It's not who you are underneath, it's what you do that defines you

c# winform DataGridView单击选中一整行,只能单选,不能选择多行,只能选择一行

设置DataGridView的属性SelectionMode为FullRowSelect 
这样就使DataGridView不是选择一个字段,而是选择一整行了 

设置DataGridView的属性MultiSelect为false 
这样就使DataGridView不能够选择多行,只能选择一行了

想得到某列的值是要判断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);
            }

转自:http://blog.163.com/ti_anzhen@126/blog/static/11856583420112312418470/

posted @ 2012-06-28 10:24  金铭杰  阅读(15170)  评论(0编辑  收藏  举报

Brick walls are there for a reason :they let us prove how badly we want things