Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

VS 2010 Switching of the DataTable RowChanged Event

$
0
0
Hi,

I have datatable that I'm updating based on a response from a server. I receive a raw value and update the row, which triggers the rowchanged event. That is fine, the problem is then I update the row with the calibrated value and the same event is triggered. Is there a way to turn the event off under certain conditions?

Here is the code I update the table with

Code:

Private Sub ReceiveMessage(Message as MyMessage)
Dim RowsAffected As DataRow()

RowsAffected = me.Store.Select("Address=" & Message.Address)    ' Store is the datatable of all rows, here I'm filtered on those with the same address field
NoRows = RowsAffected.GetUpperBound(0)

Me.Store.BeingLoadData()
For I = 0 To NoRows
RawValue = Message.Data
If RowsAffected(I).IsRawValueNull Then
' Just set the data
RowsAffected(I).RawVal = RawValue    ' RowChanged Event Triggered here
Else
If Not RawValue = RowsAffected(I).RawVal Then
RowsAffected(I).RawVal = RawValue  ' RowChanged Event Triggered here
End If
End If
Next I
Me.Store.EndLoadData()
End Sub

Here is the event handler
Code:

' I add the handler for this during initialisation using addhandler MyTable_RowChanged, AddressOf DataValues_Changed
Private Sub DataValues_Changed(ByVal Sender as Object, ByVal e As DataRowChangeEvent)
Select Case e.Action
Case System.Data.DataRowAction.Change
e.row.beingedit()
Dim CalValue = e.row.RawVal * CalNumber  ' This cal number doesn't matter for the sake of this thread!
e.row.CalibratedValue = CalValue
e.row.endedit()      ***** THIS IS THE PROBLEM ***
End Select
End Sub

To clear any confusion with the e.row.calibratedvalue, these were created using the data source wizard - hence are in the drop down list. I have used DataTable and DataRow above in place of the names of the classes of my wizard created tables etc..

So where I have highlighted "THIS IS THE PROBLEM" is where the same event handler seems to be called again, which of course I don't want. I only want the event to trigger when the raw value column is updated. Is there a simple way to do this?

Thanks,
N

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>