ColumnChanging event and boolean data type in Datagrid, BUG?

G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top