Can you handle datatable events in UiPath?

Hi All,
I have a use case where I would like to handle RowChanged event.
That is , in .NET you would normally write something like:

’ Add RowChanged event handler for the table.
AddHandler itemsTable.RowChanged, AddressOf Row_Changed

Private Sub Row_Changed(ByVal sender As Object, _
ByVal e As DataRowChangeEventArgs)
Console.WriteLine(“Row changed {0}{1}{2}”, _
e.Action, ControlChars.Tab, e.Row.ItemArray(0))
End Sub

Is this type of code supported in UiPath ? In other words, could I write a sub to handle change in a datatable or in general any other .NET object which support delegates and events ?

Thank you for your reply!

Hi sam
Create a data table and then use for each item and call datatable and use add data row where we can add data row in dt based on item


Thanks for reply.

What I am really looking for is to handle events as they occur ! .NET delegates and even handlers equivalent …

Hi Sam_Marko
I don’t think it is possible in handling Delegates through uipath

Ashwin S

Hi @Sam_Marko

You can achieve it in at least a limited extent using lambda event handler approach inside an Invoke code activity using the following synthax

AddHandler dt.RowChanged, Sub(sender As Object,e As DataRowChangeEventArgs) MsgBox("Row changed for Customer: " & e.Row("Name").tostring)

Note that the Invoke code will not provide you with the intelisense for the event but you can still use thems.

Attaching you a small demo example.
Main.xaml (7.9 KB)


Attaching you small example


this is awesome ! thanks @Florent_Salendres
I was looking for this.

Now this is very interesting … I did not know we can use Invoke Code in this way. I wonder what other ways Invoke Code can help with ? inspecting the code: is this a special way of writing multiple subs in a single code ? can you clarify the syntax a little bit…



You cannot write inside the invoke code activity as you would do in a code file (because it is not based in a code file but is effectively getting invoked trough an anonymous multi-line method (or delegate). I’m adding a snippet (to be paste inside the invoke code) that show you an example also demonstrate how you could use different subs inside it by the way of actions - there might be a different way but this is the first thing coming into my mind now.

Regarding what you can put inside an invoke code, it would be effectively what is between Sub() and End Sub, the constructor of the action

Dim a As New System.Action(Sub()
msgbox(“This is the action A”)
End Sub)
Dim b As New System.Action(Sub()
msgbox(“This is the action B”)
End Sub)

For i As Integer = 1 To 5
If i < 2 Then a.Invoke Else b.Invoke

Here the actions only contain messageboxes but you should be able to insert other statements in the subs

Hope this somehow clarifies you interrogations.

1 Like

thanks @Florent_Salendres very informative… I was looking for a reference manual around that…
very useful info. I am intrigued that the handler sub code is still get called as a callback sub, even though the activities would occur later in the workflow. It means that the code somehow gets compiled behind the scene and can then get loaded in memory as part of the program.
if you got any docs or references around the internals, would be very useful…

I am not yet sure how i could get output data from the Invoke Code sub. When I tried using Arguments with direction of Out or In/Out , the error message states that ByRef parameters are not supported in lambda expressions. So what could be the solution to expose variables out to other workflow activities ? for example, I need the text string from the Invoke Code for use with other activities.
Any pointers ?

i think i am pushing the limits with this (trying to study lambda expressions)…


I don’t think you can have you can output your action outisde the invoke code and by extention out of the workflow however, for other variable types, there should not be an issue. Could you share concrete workflow example of what you want to do?

You can find some info here regarding lambdas, not specifically applying to delegate tho…