Hosting a Control in DataGridView Cell and validation

Joined
Apr 23, 2008
Messages
1
Reaction score
0
Hi

I was watching a video:

http://windowsclient.net/learn/video.aspx?v=13416

about Data Validation on an edit record form.

Let us say now that we want to do the same in inline edit in a grid with
Hosting a Control in Windows Forms DataGridView Cell.

Now, as can be seen from a video, the correct behaviour is, that if a user is in some
text box(=cell in this case) and he enters invalid data, he can still be able to go to some
other textbox. We must NOT keep him (or not allow him to go out of the field) in the textbox
that has invalid data. It is possible that he does not know the valid data for the moment.
What we must do is just inform him with a warning (and additionally not allow him to Save a record).
Now what my problem is:
When I tried to implement the same functionallity within a grid view with the code:

internal class IntegerEditingControl : TextBox, IDataGridViewEditingControl
{
private DataGridView dataGridView;
private ErrorProvider errorProvider;
public IntEditingControl()
{
}
private void OnCellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (dataGridView.EditingControl != null &&
dataGridView.EditingControl.GetType() == typeof(IntEditingControl))
{
string error = errorProvider.GetError(this);
if (!string.IsNullOrEmpty(error))
{
// Data entered in a cell is Invalid
// Only if we cancel it, then the correct icon is shown with the message of errorprovider
e.Cancel = true;
}
}
}
...
// implementation of a IDataGridViewEditingControl
public DataGridView EditingControlDataGridView
{
get { return dataGridView; }
set
{
dataGridView = value;
dataGridView.CellValidating += OnCellValidating;
}
}
I get an error icon nicely painted and shown Only if I call e.Cancel = true in OnCellValidating method.
But I actually do not want this, since the focus stays in a editing cell. I want to go normally to some other cell, and (as in the video) only warn the user with an error icon (and appropriate error text).
If I do not call this e.Cancel = true; then the error icon is not shown!?
Can you help me with this; I can also provide you with a sample project if you need it.

Or a least justify this .net solution, so I can talk to my customer why the two
different standards. One if I open an edit form and allow him to go out of a cell=textbox which
has an invalid input and the other when we input data directly in a grid, where I "Must not" allow him to get out of a cell.
Thank you for your help and any answer.

Regards,
Sebastijan
 

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