gridview 的SelectedIndexChanging 可以在Winform里的Click里实现
例如行的变化,获取行变化的值
if (dataGridView1.Rows.Count > 0)
{
string str = dataGridView1.SelectedRows[0].Cells["WOID"].Value.ToString();
label1.Text = str;
}
gridview 的RowDataBound 可以在Winform里的RowPrePaint里实现
例如在某值范围内改变字体颜色或行背景颜色
if (e.RowIndex >= dataGridView1.Rows.Count - 1)
{
return;
}
DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
if (Convert.ToInt32(dgr.Cells["WOID"].Value.ToString()) > 4)
{
dgr.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
dgr.DefaultCellStyle.BackColor = System.Drawing.Color.Blue;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}