views:

63

answers:

1

If a user enters invalid text in a DataGridView's cell I want to prevent the user from leaving that cell and display an error icon in that cell with an error message in a tooltip. It seems that normally the error icon won't appear until the cell is no longer in edit mode. I found an example of how to get the error icon to appear while it's still in edit mode, but the tooltip won't show up when I hover over it.

I'm using Windows 7, but I couldn't get it to work in XP either, so we can rule that out.

Can anybody figure out what the example is missing or suggest an alternative approach that would yield the same results?

To get the example working you'll need to create your own form, copy/paste the example code, add using System.Drawing.Drawing2D;, and assign the event handlers yourself.

+1  A: 

I suggest you look at IDataErrorInfo interface

For example see the following post.

Jacob Seleznev
Thanks! I'll play around with this today.
Ecyrb
I'm not sure this will work for me. The documentation is worthless. I checked out the post and even the blog that one of its answers linked to, but that didn't help me understand how to get it working properly with my `DataGridView`. I don't see how I can use this to prevent a user from entering an invalid `DateTime` (like null or "Blarg"). For normal string columns, it wouldn't validate until after the cell lost focus, which defeats the purpose of my goal. Maybe I just don't know how to use it properly. Any additional examples relating to `DataGridView` would be most welcome.
Ecyrb