How to "cancel" a proposed change in a columnChanging event

How to "cancel" a proposed change in a columnChanging event

Post by Mitc » Fri, 26 Jul 2002 06:00:05



I ahve a grid bound to a datatable. When I get a columnchanging event, I do
some verification. Unfortunately, even when I detect an error, I don't know
how to stop the value from being changed. I tried using the row's cancelEdit
and the rejectChanges methods, but these do not stop the update.

private void ColumnChanging(object sender, DataColumnChangeEventArgs e)
{
     if (e.ProposedValue.ToString() == "foo")
     {
          MessageBox.Show("foo is not a legal value");
          e.Row.CancelEdit();
     }

Quote:}

Thanks,

Mitch

 
 
 

How to "cancel" a proposed change in a columnChanging event

Post by .net datagridcolumnstyle » Fri, 26 Jul 2002 06:56:51


Hi Mitch
You need to throw an exception to get the change to be ignored.
You might also want to raise an event to enable you to tell the user
something is not right as throwing an exception will reset the value in the
cell that is being changed quite quietly.

Hope that helps

Jasmine
www.datagridcolumnstyles.net
Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid


Quote:> I ahve a grid bound to a datatable. When I get a columnchanging event, I
do
> some verification. Unfortunately, even when I detect an error, I don't
know
> how to stop the value from being changed. I tried using the row's
cancelEdit
> and the rejectChanges methods, but these do not stop the update.

> private void ColumnChanging(object sender, DataColumnChangeEventArgs e)
> {
>      if (e.ProposedValue.ToString() == "foo")
>      {
>           MessageBox.Show("foo is not a legal value");
>           e.Row.CancelEdit();
>      }
> }

> Thanks,

> Mitch


 
 
 

How to "cancel" a proposed change in a columnChanging event

Post by Robert Christia » Fri, 26 Jul 2002 10:18:04


can you not just change e.proposed back to the original value?


Quote:> I ahve a grid bound to a datatable. When I get a columnchanging event, I
do
> some verification. Unfortunately, even when I detect an error, I don't
know
> how to stop the value from being changed. I tried using the row's
cancelEdit
> and the rejectChanges methods, but these do not stop the update.

> private void ColumnChanging(object sender, DataColumnChangeEventArgs e)
> {
>      if (e.ProposedValue.ToString() == "foo")
>      {
>           MessageBox.Show("foo is not a legal value");
>           e.Row.CancelEdit();
>      }
> }

> Thanks,

> Mitch