Data type enforcement in DataGridView

W

wannabe geek

I want to know the best way to enforce data types (double, string) in a
DataGridView control. The control would be unbound and programmatically
populated. TIA.
 
J

Jeff Johnson

I want to know the best way to enforce data types (double, string) in a
DataGridView control. The control would be unbound and programmatically
populated. TIA.

I'd start by looking at the CellEndEdit event.
 
W

wannabe geek

Jeff Johnson said:
Actually, it looks like the CellValidating event might be an even better
choice.


.

Is there a way to get .NET to validate data based on specific types or must
i do that manually and display error messages?
 
J

Jeff Johnson

Is there a way to get .NET to validate data based on specific types or
must
i do that manually and display error messages?

No idea. I always handle validation manually, so I've never even tried to
see if .NET can do it for me.
 
A

Andy O'Neill

wannabe geek said:
Is there a way to get .NET to validate data based on specific types or
must
i do that manually and display error messages?

Yes.
But you would need to bind to something that has the types.
You could build a datatable programmatically with all the right field types
and set the length of text columns etc
Then bind to that.
If you put a letter in a numeric column it'll throw an error for you.
Not a terribly user friendly error but there may be a way to over-ride it.
While since I did winforms.
 
W

wannabe geek

Andy O'Neill said:
Yes.
But you would need to bind to something that has the types.
You could build a datatable programmatically with all the right field types
and set the length of text columns etc
Then bind to that.
If you put a letter in a numeric column it'll throw an error for you.
Not a terribly user friendly error but there may be a way to over-ride it.
While since I did winforms.

.

Thanks. I guess I will attempt to do it manually then.
 

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