设置控件选中一整行
设置DataGridView的特点SelectionMode为FullRowSelect
这样就使DataGridView不是挑选一个字段,而是挑选一整行了
设置只能选中一行
设置DataGridView的特点MultiSelect为false
这样就使DataGridView不能够挑选多行,只能挑选一行了
得到选中行某列的值
string str = dataGridView1.CurrentRow.Cells[2].Value.ToString();
得到选中行的索引
int intRow = dataGridView1.SelectedCells[0].RowIndex;
得到列的索引
int intColumn = dataGridView1.SelectedCells[0].ColumnIndex;
改动行的色彩
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Green;
设置单元格不行修改
DataGridView.ReadOnly特点改为True;