Solved

Question about datagridview component in vs 2005

Posted on 2006-06-26
13
796 Views
Last Modified: 2008-01-09
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
Comment
Question by:rutledgj
  • 7
  • 5
13 Comments
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16986992
cell.ErrorText = errorMessage

no?
0
 

Author Comment

by:rutledgj
ID: 16987478
Thanks but I've tried that and I don't see any msg. Also, how do you show the error icon?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16987700
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:rutledgj
ID: 16991628
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16995373
What are the cell bounds?  What are the cell icon bounds?

Bob
0
 

Author Comment

by:rutledgj
ID: 16996361
Hey,

    That's why I'm asking the question. I don't know how you do this!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16996671
How wide is the column?

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16996685
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16996697
You need to query cell.EditedFormattedValue instead of cell.Value.

Bob
0
 

Author Comment

by:rutledgj
ID: 16996757
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 125 total points
ID: 16996784
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
 

Author Comment

by:rutledgj
ID: 16996929
so does this allow for room in the cell for the error icon?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16997307
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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question