b h

b h

  • NA
  • 11
  • 0

Datagrid validation

Nov 9 2006 2:00 PM
I am using VS 2003.  I have a strange thing happening and not sure why.  I copied some code from another datagrid that is working ok, but for some reason this one is not.  The Validating event is firing on any click, keystroke, etc.  In other words, if the I enter a 3 in the column, it fires, then fires again when I enter another 3. So if I enter 33333 in the column, it fires 5 times, and also fires if I trigger an error with a message box.  The code is below:

DataGridTextBoxColumn colOrder = new DataGridTextBoxColumn();

colOrder.MappingName = "ORDER_NUMBER";

colOrder.HeaderText = "Work Order";

colOrder.Width = 75;

colOrder.ReadOnly = false;

colOrder.NullText = string.Empty;

colOrder.TextBox.Validating += new CancelEventHandler(Order_Validate);

dataGridTableStyle2.GridColumnStyles.Add(colOrder);

.

.

.

private void Order_Validate(Object sender, CancelEventArgs e)

{

TextBox txt = sender as TextBox;

if (!checkWorkOrder(txt.Text))

e.Cancel = true;

else

e.Cancel = false;

}