Datagrid Issues

M

Megan

I'm currently trying to develop a solution containing a bound DataGrid
that allows insert and update functions. I'm having 2 problems that
i'd appreciate some help with.

The first problem is where I have a primary key field that I don't
want users to be able to modify. The obvious solution is to configure
the column to be read only. However, then when a user tries to insert
a record, that column is still read only and so nothing can be
entered.

The second problem i'm having is to do with validation. I have a
RowChanging event on the underlying DataTable that validates the data
and if there are any problems uses SetColumnError to flag the issue to
the user. I also have a Validating event on the DataGrid that I use to
confirm that there are no errors before a user can leave the grid. The
problem is that the RowChanging and Validating events both fire at the
same time. So that if a value is changed to an invalid value and then
the grid is left, the value has not been flagged as an error when the
Validating event runs.

I hope I have explained these issues well enough. Any help or
suggestions would be welcomed.
 
A

Alok

Megan,
Regarding the first issue..
Could you not set the primary key constraint on the dataset itself, instead
of changing the column styles.
For the second problem, i don't think you need to handle both the validating
and the row changed event. only the row changed should suffice.
 
M

Megan

Setting the primary key on the underlying DataTable does not stop the
user from being able to modify the primary key field(s) within the
DataGrid.

I want the row changed event to check the modified data for errors.
But if there are errors, I simply use the SetColumnError function to
flag these as errors (ie: it doesn't stop errors from being entered,
just lets the user know of the problem). I therefore then need the
validating event to ensure that all errors have been fixed before the
grid is left. It is only after this (ie: in the validated event) that
the changes made in the grid get written back to the database.

Hope this clears things up a little.
 

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