What i want to do is like this: if there is error in the cell, then the cursor cannot leave the cell and the back color of the cell should be red.
But the line to change backcolor didn't take effect, do you know why??
private
void ultraGrid1_BeforeExitEditMode(object sender, BeforeExitEditModeEventArgs e) { ......
{
......
e.Cancel =
true;
}
While their investigation is in progress, here's a method that should work fine. I tested it as far back as 2010 Volume 2.
private void ultraGrid1_BeforeExitEditMode(object sender, Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs e) { bool hasError = true; if (hasError) { this.ultraGrid1.DisplayLayout.Override.ActiveCellAppearance.BackColor = Color.Red; e.Cancel = true; } else { this.ultraGrid1.DisplayLayout.Override.ActiveCellAppearance.BackColor = Color.White; } }
Or if you need Mike's fix that includes a text box, here's the snippet for that.
private void ultraGrid1_BeforeExitEditMode(object sender, Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs e) { bool hasError = true; if (hasError) { this.ultraGrid1.DisplayLayout.Override.ActiveCellAppearance.BackColor = Color.Red; if (this.ultraGrid1.Controls.Count > 0) { TextBox textBox = this.ultraGrid1.Controls[0] as TextBox; if (textBox != null) textBox.BackColor = Color.Red; } e.Cancel = true; } else { this.ultraGrid1.DisplayLayout.Override.ActiveCellAppearance.BackColor = Color.White; } }
yes, i tested the way provided in upstairs, it works. Thank you very much.
Also thank you Mike for your help and quick response. And thanks Chris.
Hi,
I just wanted to let you know, I looked into this a little deeper and I discovered the problem. The reason this.ultraGrid1.ActiveCell.Appearance has no effect is that the backcolor is being overriden by the ActiveCellAppearance and the ActiveRowAppearance.
So you have to either turn these off:
this.ultraGrid1.DisplayLayout.Override.ActiveCellAppearance.Reset();this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance.Reset();
Or set both the Appearance and the ActiveAppearance on the cell.
this.ultraGrid1.ActiveCell.Appearance.BackColor = Color.Red;this.ultraGrid1.ActiveCell.ActiveAppearance.BackColor = Color.Red;
This, of course, explains why it works when you use the ActiveCellAppearance property.