目的是当当前cell离开时做验证,如果验证不通过,设置为红色背景色并且字符全选现在,在CellValidating事件中写了设置,可是只要e.Cancel = true就不显示设置的背景色
还有DataGridViewTextBoxCell中没有,selectall方法 private void uvasBaseGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
DataGridViewColumn clmCurren = uvasBaseGridView1.Columns[e.ColumnIndex];
if (clmCurren.Name == "SALE")
{ if (int.Parse(uvasBaseGridView1.CurrentCell.EditedFormattedValue.ToString()) > 99999)
{ //MessageBox.Show("max input number is 99999"); DataGridViewTextBoxCell tb = (DataGridViewTextBoxCell)uvasBaseGridView1.CurrentCell; tb.Style.BackColor = System.Drawing.Color.Red; e.Cancel = true;
}
} }
还有DataGridViewTextBoxCell中没有,selectall方法 private void uvasBaseGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
DataGridViewColumn clmCurren = uvasBaseGridView1.Columns[e.ColumnIndex];
if (clmCurren.Name == "SALE")
{ if (int.Parse(uvasBaseGridView1.CurrentCell.EditedFormattedValue.ToString()) > 99999)
{ //MessageBox.Show("max input number is 99999"); DataGridViewTextBoxCell tb = (DataGridViewTextBoxCell)uvasBaseGridView1.CurrentCell; tb.Style.BackColor = System.Drawing.Color.Red; e.Cancel = true;
}
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货