Results 1 to 2 of 2

Thread: DGV Error Providing Ideas

  1. #1

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    DGV Error Providing Ideas

    I now have a DataGridView that has a bit of validation on it. I don't think I have ever used a DGV in this fashion, so I've gotten to learn a few things. One of the things I've learned is that validation and providing feedback for the users is a bit fiddly and open ended. At this point, I am using a modified variation on this SO approach:

    https://stackoverflow.com/questions/...r-datagridview

    I shifted things around a bit, and it is working fine, as far as I can tell, but it's perhaps not ideal for a couple reasons, and I would think people might have other ideas that they prefer. By using my variation on that thread, I get an error icon on the right side of the cell, and the user can't move out of the cell. That's pretty fair feedback. The icon oddly flickers, at times, and I haven't quite figured out why (it almost certainly has to do with where the mouse is located), but it's good enough that I'm not overly concerned about it.

    However, I also have a means to flood fill the columns in the DGV. This will fill all the cells in a column with the same value. I can't think of a scenario where errors will arise from doing this, because the flood fill does it's own validation prior to putting anything in the cell, but if I'm wrong about that, it seems like there would be an odd failure mode, as one value would update, that would get rejected by the validating, and the loop that was flood filling would freeze. I would expect this would lock up the interface.

    Again, I don't think this is possible, but it suggests that some other form of validating might make more sense.

    So, I was wondering what methods people have used for validating DGV cell contents, and providing feedback to the user? I'm looking for better ideas than the one I'm using.
    My usual boring signature: Nothing

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    846

    Re: DGV Error Providing Ideas

    this how I validate a dgv in one of my application. it is an old one so maybe not the most efficient

    I enter manually values to create a list of point for a curve, the dgv checks several things before updating the curve object

    Code:
    'update of the graph with new info in the DGV
       'check if any empty cell before updating the curve object
       Private Sub DataGrid_Courbe_RowValidating(ByVal sender As Object, ByVal data As DataGridViewCellCancelEventArgs) Handles DataGrid_Courbe.RowValidating
          Dim row As DataGridViewRow = DataGrid_Courbe.Rows(data.RowIndex)
    
          'if both cells are empty in the same time, it is not a problem
          If row.Cells(DataGrid_Courbe.Columns(0).Index).Value Is DBNull.Value AndAlso row.Cells(DataGrid_Courbe.Columns(1).Index).Value Is DBNull.Value Then
             data.Cancel = False
             'if one cell is empty, warn the user
          ElseIf row.Cells(DataGrid_Courbe.Columns(0).Index).Value Is DBNull.Value AndAlso row.Cells(DataGrid_Courbe.Columns(1).Index).Value IsNot DBNull.Value Then
             row.Cells(DataGrid_Courbe.Columns(0).Index).ErrorText = "Valeur manquante" 'mean missing value'
             data.Cancel = True
    
          ElseIf row.Cells(DataGrid_Courbe.Columns(1).Index).Value Is DBNull.Value AndAlso row.Cells(DataGrid_Courbe.Columns(0).Index).Value IsNot DBNull.Value Then
             row.Cells(DataGrid_Courbe.Columns(1).Index).ErrorText = "Valeur manquante"
             data.Cancel = True
    
          Else
             row.Cells(DataGrid_Courbe.Columns(0).Index).ErrorText = ""
             row.Cells(DataGrid_Courbe.Columns(1).Index).ErrorText = ""
          End If
       End Sub
    
       'check if a stupid user don't put numbers
       Private Sub DataGrid_Courbe_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGrid_Courbe.DataError
          MessageBox.Show("le format est incorrect")
          e.ThrowException = False
    
       End Sub
    
       'if validating is ok , update the curve
       Private Sub DataGrid_Courbe_RowValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid_Courbe.RowValidated
          maj_courbe()
       End Sub
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width