Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 815
  • Last Modified:

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
0
rutledgj
Asked:
rutledgj
  • 7
  • 5
1 Solution
 
vb_jonasCommented:
cell.ErrorText = errorMessage

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

Bob
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rutledgjAuthor Commented:
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
0
 
Bob LearnedCommented:
What are the cell bounds?  What are the cell icon bounds?

Bob
0
 
rutledgjAuthor Commented:
Hey,

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

Bob
0
 
Bob LearnedCommented:
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
0
 
Bob LearnedCommented:
You need to query cell.EditedFormattedValue instead of cell.Value.

Bob
0
 
rutledgjAuthor Commented:
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.

0
 
Bob LearnedCommented:
Try this:

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 = grd1(e.ColumnIndex, e.RowIndex)
            If IsNumeric(cell.EditedFormattedValue) Then
               cell.ErrorText = ""
            Else
               cell.ErrorText = "Invalid Data:  Cell value must be numeric"
            End If
        End If
       
End Sub

Bob
0
 
rutledgjAuthor Commented:
so does this allow for room in the cell for the error icon?
0
 
Bob LearnedCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now