Results 1 to 7 of 7

Thread: [2005]DataGridView Error Handleing advice.

  1. #1

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    [2005]DataGridView Error Handleing advice.

    Greetings Community...

    I Need advice.

    I have created an error handler for a DatagridView. I want to know if this is the most efficient way to handle the event or might one of you see a quicker more consice method.THe handler works but i think it may not be as clean as it could be. The event is catching a invalid commit event.

    Code:
    Private Sub EQ_EquipmentDataGridView_DataError(ByVal sender As  Object,
     ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs)
     Handles EQ_EquipmentDataGridView.DataError
            
            Dim errorContext As String = "Commit"
    
            If errorContext = CStr(e.Context) Then
                Try
                    Me.EQ_EquipmentDataGridView.CancelEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
    End Sub
    Any advice is appreciated.
    Last edited by smilbuta; Apr 3rd, 2007 at 02:48 PM.

  2. #2
    Member
    Join Date
    Apr 2007
    Posts
    36

    Re: [2005]DataGridView Error Handleing advice.

    is the datgridview bound to a source or is the user entering the data? what is typically happening when the error comes up? the direction that I'm going is, are users typing data into the datagridview that the datagridview doesn't like?

  3. #3

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: [2005]DataGridView Error Handleing advice.

    Well yes.
    All of the feilds must be populated with data or a selction from the comboboxes. If a user failes to fill a feild out it usualy threw a long exception but now it simply canceledit on the row in question.

    My question was can someone show me a more "clean " way of dealing with this error. Possibly not removing the imputed data and just simply telling the user a feild was missed and or moving focus PRE commit to the empty cell.

  4. #4
    Member
    Join Date
    Apr 2007
    Posts
    36

    Re: [2005]DataGridView Error Handleing advice.

    might seem like i'm asking the same question again here, but the comboboxes that the users are filling in - are they standard comboboxes located somewhere else on the form are are they typing into a DataGridViewComboBoxCell?

  5. #5
    Member
    Join Date
    Apr 2007
    Posts
    36

    Re: [2005]DataGridView Error Handleing advice.

    if the users are editing directly in the datagridview heres the doc that used to do something similar: http://www.windowsforms.net/Samples/...View%20FAQ.doc

    This isn't a one line fix but when you get it working, it just has 'that feel'
    Look at the 'order of validation events' section and the section right after it on 'data validation'. if I understand what you're looking to do, you'll want to handle the CellValidating event, as DataGridViewCellValidatingEventArgs give you the option (by setting e.Cancel = True) to reset the cell or change the value of the cell before the dataError event triggers.
    Later in that section there is also a link for displaying a little error icon in the grid so the user can see that something is amuck.

    also, if you have a combo in the datagridview and you want to mimic the behavior of the dropdownlist style (where the user can pick from values in the list but can't type freely) look into EditingControlShowing

    or maybe I completely misunderstood..

  6. #6

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: [2005]DataGridView Error Handleing advice.

    YEs, excatly .. I wish to handle the Error Event after the user has input data and before the move to a new row. Ill read over the Link you provided... THanx.

  7. #7
    Member
    Join Date
    Apr 2007
    Posts
    36

    Re: [2005]DataGridView Error Handleing advice.

    YOu're welcome.

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