DataTable.TableClearing Event doesn't fire when clearing empty tab

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

According to the documentation TableClearing will be fired even when empty
tables are cleared:

"The TableClearing event is fired before processing of the Clear operation
begins. This event is always fired when the Clear method is invoked, even if
the table contains zero rows."

Add this code to a empty form:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Create table with one column
Dim dt As New DataTable
dt.Columns.Add("col1", System.Type.GetType("System.String"))

' Create row
Dim dr As DataRow = dt.NewRow
dr(0) = "val1"

' Add event handler
AddHandler dt.TableClearing, New
DataTableClearEventHandler(AddressOf TableClear)

' Clear table
dt.Clear()

' Add the row
dt.Rows.Add(dr)

' Clear table again
dt.Clear()
End Sub

Private Sub TableClear(ByVal sender As Object, ByVal e As
DataTableClearEventArgs)
MsgBox("Event fired!")
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

As you will see the event is only fired once, but I think it should be fired
twice. Is this a bug or have I done something wrong?
 
Hello,

Based on my test, you are right at this issue. If DataTable has no record,
then when calling Clear() function, DataTableClearEventHandler was never
fired.

It seems to be a mistake in the document. Thank you for sharing the
experience in the community.

Luke
 
Back
Top