Link to home
Start Free TrialLog in
Avatar of rutledgj
rutledgj

asked on

Question about datagridview component in vs 2005

I want to know how make an error icon display in the cell of the unbound datagridview.

I've read where this is possible but I can't find code that shows how to make it appear/disappear. I also believw you can set an error tooltip also.

Thanks
Rut
Avatar of vb_jonas
vb_jonas
Flag of Sweden image

cell.ErrorText = errorMessage

no?
Avatar of rutledgj
rutledgj

ASKER

Thanks but I've tried that and I don't see any msg. Also, how do you show the error icon?
Avatar of Bob Learned
What is the setting for ShowCellErrors?  If it is set to True, when you set Error text, you should get an icon.

Bob
ShowCellError is set to true. Here is the code I'm using:

Private Sub grd1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles grd1.CellValidating

        If grd1.IsCurrentCellDirty Then
            grd1.ShowCellErrors = True

            Dim cell As DataGridViewCell
            cell = grd1(e.ColumnIndex, e.RowIndex)
            If IsNumeric(cell.Value) Then
                Exit Sub
            End If
            cell.ErrorText = "Invalid Data"

           
        End If
       

    End Sub
What are the cell bounds?  What are the cell icon bounds?

Bob
Hey,

    That's why I'm asking the question. I don't know how you do this!
How wide is the column?

Bob
I see another problem:

  If you are checking grd1.IsCurrentCellDirty, then the data hasn't been saved to the grid yet, and so you can't query the cell for the value with cell.Value.

Bob
You need to query cell.EditedFormattedValue instead of cell.Value.

Bob
I guess it would be beneficial to maybe see this function coded correctly.  The cells are wide enough to display 5 digits but only 4 is allowed. I'm unsure as to how the error icon is displayed in the cell, if you can position it, or how much wider the cell needs to be to accomadate it.

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so does this allow for room in the cell for the error icon?
Yes, since you were never reaching the code that was setting ErrorText, since you were checking cell.Value.  With that code that I showed you, you be able to cell the error icon now.

Bob