views:

71

answers:

1

I have a relatively simple question regarding the best way to call the DataGridView.Rows.Add function when it is inherited into the current control. Which is the best way to make the call to the inherited control? Call it directly in the invoke or call it using recursive-like function? They both seem to produce the same result, a row gets added and the quantity is returned, but which is the most efficient?

The delegate: Private Delegate Function ReturnDelegate() As Object

The two ways are:
A)

        Private Overloads Function AddRow() As Integer
            If InvokeRequired Then
                Return CInt(Invoke(New ReturnDelegate(AddressOf AddRow)))
            Else
                Return Rows.Add()
            End If
        End Function

Or

B)

        Private Function RowsAdd() As Integer
            If Me.InvokeRequired Then
                Return CInt(Me.Invoke(New ReturnDelegate(AddressOf MyBase.Rows.Add)))
            Else
                Return MyBase.Rows.Add
            End If
        End Function
A: 

Usually I take care of efficiency by placing BeginUpdate() EndUpdate() block around my series of updates.

GregC
Keep in mind that these operations should be coded up in a transactional format: BeginUpdate(), try block with EndUpdate(true), and catch block with EndUpdate(false).
GregC
I don't see BeginUpdate and EndUpdate for the DataGridView or Rows control-- can you provide a code example?
Stevoni