I have a relatively simple question regarding the best way to call the DataGridView.Rows.Add function when i开发者_JAVA技巧t 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
Usually I take care of efficiency by placing BeginUpdate() EndUpdate() block around my series of updates.
精彩评论