Hello everyone,
It's not getting better, the more I delve into it, the more frustrated I
get. But it should be a simple thing, after all, all I'm trying to do is put
some data validation code for a column of a table.
To understand the problem more clearly I used 'Products' table of the
Northwind databse. I made a simple form that shows all the column of the
table. There is a 'bit' field in the table called 'Disontinued'. I wrote the
following code to incorporate some 'business logic' in the ColumnChanging
event for the table.
---------------------------
if (e.Column.ColumnName == "Discontinued" && (bool)e.ProposedValue)
{
if ((short)e.Row["UnitsInStock"] >= 0)
throw new Exception("You can not discontinue this product");
}
----------------------------
Several things happen when I try to do the change in the datagrid some of
which are more severe than others. When I 'tick' the corresponding field with
a mouse and istead of taking the mouse focus from the field press 'tab' to
take the input focus somewhere else, the whole thing crashes. Am I supposed
to handle the exception that I threw? Apparently not! When I use the mouse to
take the focus somewhere else, a message is shown with my exception and the
grid behaves properly.
Again, when I use mouse to go to another row on the same column (i.e.
Discontinued), the grid behaves exactly the way I want, the column gets reset
to its original 'unticked' state after I answer 'No' to the question asked by
the grid. But if I click on some other column on the same row or in another
row and give the same 'No' answer to the same question, the column value does
not get reset, it takes the newly 'ticked' state, even though I threw the
exception.
Did anyone experience similar kind of problem? I would really appreciate if
someone answers me.
Thanks in advance.

RE: ColumnChanging event and boolean data type in Datagrid, BUG? by Puspak

Puspak
Tue Dec 13 06:52:01 CST 2005

I already go an answer from Microsoft Forums on Windows Forms. Here is the
link to my other posting.... if anyone is interested..

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=165034&SiteID=1

"Puspak" wrote:

> Hello everyone,
> It's not getting better, the more I delve into it, the more frustrated I
> get. But it should be a simple thing, after all, all I'm trying to do is put
> some data validation code for a column of a table.
> To understand the problem more clearly I used 'Products' table of the
> Northwind databse. I made a simple form that shows all the column of the
> table. There is a 'bit' field in the table called 'Disontinued'. I wrote the
> following code to incorporate some 'business logic' in the ColumnChanging
> event for the table.
> ---------------------------
> if (e.Column.ColumnName == "Discontinued" && (bool)e.ProposedValue)
> {
> if ((short)e.Row["UnitsInStock"] >= 0)
> throw new Exception("You can not discontinue this product");
> }
> ----------------------------
> Several things happen when I try to do the change in the datagrid some of
> which are more severe than others. When I 'tick' the corresponding field with
> a mouse and istead of taking the mouse focus from the field press 'tab' to
> take the input focus somewhere else, the whole thing crashes. Am I supposed
> to handle the exception that I threw? Apparently not! When I use the mouse to
> take the focus somewhere else, a message is shown with my exception and the
> grid behaves properly.
> Again, when I use mouse to go to another row on the same column (i.e.
> Discontinued), the grid behaves exactly the way I want, the column gets reset
> to its original 'unticked' state after I answer 'No' to the question asked by
> the grid. But if I click on some other column on the same row or in another
> row and give the same 'No' answer to the same question, the column value does
> not get reset, it takes the newly 'ticked' state, even though I threw the
> exception.
> Did anyone experience similar kind of problem? I would really appreciate if
> someone answers me.
> Thanks in advance.