datatable ColumnChanging event fired without data changing when binding to other property then Text RRS feed

  • Question

  • hi everyone.
    I Have a custom control that inherits from MaskEditTextBox , when the binding is to the Text property every thing is working well.
    but when the binding is to my own property there is a problem.
    after leaving the control the ColumnChanging is fired (when the Validating event occures.)
    Looking for the problem I noticet that this is happening also in the standart TextBox control when the binding is to Other property than "Text" property such as "Tag".
    In the custom control this can be solved by commiting the base.Validating only when value changed but when there is a Grid Bounded to the same DataSource as the custom control moving on the grid between the records the Validating event is not raised (in the Custom control ) and the  ColumnChanging  raised by the Datatable and the GetChanges() datatable method return a changes set
    wthout changing the value in the custom control.
    is anyone is familiar with this Problem ? or knows a work a round for this .
    a code snipet :

    there 3 standart maskedit text boxes a button
    clicking on the button will do the binding .
    the maskedTextBox3 is binded with the "Tag" property.
    after leaving the control  you'll see that the event ColumnChanget is fired.
    Thanks .


    DataTable dt;


    DataRow dr;


    public Form1()






    private void prvCreateDataTable()


    dt =

    new DataTable();


    "Col1", typeof(string));


    "Col2", typeof(string));

    dr = dt.Rows.Add();


    "Col1"] = "Col1";


    "Col2"] = "Col2";



    dt.ColumnChanging +=

    new DataColumnChangeEventHandler(dt_ColumnChanging);

    dt.GetChanges().Rows.Count > 0;



    private void dt_ColumnChanging(object sender, DataColumnChangeEventArgs e)






    MessageBox.Show("ColumnChanging: " + e.Column.ColumnName +


    "\n origional value: " + e.Row[e.Column.ColumnName, DataRowVersion.Original].ToString() +


    "\n Current Value:" + e.Row[e.Column.ColumnName].ToString() +


    "\n proposed value: " + e.ProposedValue.ToString()




    catch (Exception)








    private void button1_Click(object sender, EventArgs e)



    "Text", dt, "Col1", true, DataSourceUpdateMode.OnPropertyChanged);


    "Text", dt, "Col2", true, DataSourceUpdateMode.OnPropertyChanged);


    "Tag", dt, "Col2", true, DataSourceUpdateMode.OnPropertyChanged);


    Monday, May 4, 2009 3:07 PM


All replies