Solved

Question about datagridview component in vs 2005

Posted on 2006-06-26
13
771 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now