设置DataGridView的属性SelectionMode为FullRowSelect
这样就使DataGridView不是选择一个SEO靠我字段,而是选择一整行了
设置DataGridView的属性MultiSelect为false
这样就使DataGridView不能够选择多行,只能选择一行了想得到某列的值是要判断DataGridView是SEO靠我否有选中的行
if (dataGridView1.SelectedCells.Count != 0)
{
//得到选中行的索引
int intRow = dataGridView1.SelectedCellsSEO靠我[0].RowIndex;//得到列的索引
int intColumn = dataGridView1.SelectedCells[0].ColumnIndex;//得到选中行
某列的值
string stSEO靠我r = dataGridView1.CurrentRow.Cells[2].Value.ToString();
MessageBox.Show(str);
}for (iSEO靠我 = 0; i < dataGridView1.Rows.Count - 1; i++){if(..................){ dataGridView1.Rows[SEO靠我i].DefaultCellStyle.BackColor = Color.Green;}
}网站备案号:浙ICP备17034767号-2