|
Refreshing the data calling my load and draw procedures wont fire in my normal sub |
Posted by Jeff on Jan-20-2025 12:37 |
|
Below is the winchartviewer mouse move event.
I call a loaddata() and drawChart() from my own procedure. the draw is ignored.
But if I call the above two within a WinchartViewer1 event, it fires. My solution is less than ideal:
Private Sub WinChartViewer1_MouseMove(sender As Object, e As MouseEventArgs) Handles WinChartViewer1.MouseMove
If isDragging Then
'Cursor = Cursors.Hand ' Ensure the drag cursor stays
'WinChartViewer1.Cursor = Cursors.Hand
Cursor = RectangleCursor()
WinChartViewer1.Cursor = RectangleCursor()
WinChartViewer1.HotSpotCursor = WinChartViewer1.Cursor
End If
If ForceRebuild = True Then
ForceRebuild = False
loadData()
drawChart(WinChartViewer1)
End If
End Sub
The calling procedure is bellow: if i call :
loadData()
drawChart(WinChartViewer1)
Within Addchip() it wont work. Is there a winchartviewer1 scope issue? both the winchartviewer1 and the below procedure are in the same Form class. The below procedure just adds a floating bar record to the data and the data looks correct after the loadData() call.
Public Sub AddChip(ByVal StationOrder As Integer, ByVal Description As String, ByVal ValueAddedString As String, ByVal DelayString As String, ByVal sngVal As Single, ByVal Staffing As Integer, ByVal Occurance As Integer, ByVal StartTime As Single, ByVal StopTime As Single, ByVal VideoFilename As String, Optional ByVal ChipOrder As Integer = -1, Optional Notes As String = "", Optional sngFrequency As Single = 1)
If AddEditFlag = "Add" Then
'Chip Unique ID
Dim currentDate As Date = Date.Now
Dim Ticks As Long = currentDate.Ticks
Select Case ChipOrder
Case 9999
'Append
Dim MaxChipOrderdt As DataTable = DsCommand.ExecuteToTable("SELECT MAX(ChipOrder) FROM Chips WHERE StationOrder = " & StationOrder, Baldataset)
If MaxChipOrderdt.Rows(0).Item(0) > 0 Then
ChipOrder = MaxChipOrderdt.Rows(0).Item(0) + 1
Description = Replace(Description, "'", "''")
SQL = "INSERT INTO Chips(StationOrder, ChipOrder, Description, ValueAdded, DelayAvoidUnavoid, sngValue, Staffing, Occurs, Ticks, StartTime, StopTime, VideoFilename) VALUES(" & StationOrder & "," & ChipOrder & ",'" & Description & "','" & ValueAddedString & "','" & DelayString & "'," & sngVal & "," & Staffing & "," & Occurance & "," & Ticks & ", " & StartTime & "," & StopTime & ", '" & VideoFilename & "')"
Result = DsCommand.ExecuteNonQuery(SQL, Baldataset)
Baldataset.AcceptChanges()
'SET a global force rebuild flag so mousemove can sense it
ForceRebuild = True
Threading.Thread.Sleep(100)
End If
End Select
End If
End Sub |
Re: Refreshing the data calling my load and draw procedures wont fire in my normal sub |
Posted by Peter Kwan on Jan-20-2025 20:38 |
|
Hi Jeff,
I assume you mean if the loaddata() and drawChart(WinChartViewer1) is in the MouseMove event handler, and the ForceBuild is True, then the chart is drawn normally.
If the loaddata() and drawChart() is in the AddChip function, then it does not work.
To check if your code has really call "loadData" or "drawChart", please put a System.Diagnostics.Debug.WriteLine code in these two functions, like:
' In the first line of the loadData Fucntion
System.Diagnostics.Debug.WriteLine("Inside loadData " & DateTime.Now.ToString("HH:mm:ss"))
' In the first line of the drawChart Fucntion
System.Diagnostics.Debug.WriteLine("Inside drawChart " & DateTime.Now.ToString("HH:mm:ss"))
The above code will generate a line in the Output window in Visual Studio, so you can verify the functions are called.
In your charting code, please change the chart title to:
c.addTitle(DateTime.Now.ToString("HH:mm:ss"))
Now you should see a timestamp in the chart title. If the chart tile changes, it means the chart has changed. If the chart title changes, but the chart graphics does not change, it means may be your data have not changed so it draws the same chart.
I wonder why there is a Threading.Thread.Sleep(100) in addChip. In the addChip runs in the main thread, it hangs the main thread. The GUI lives in main thread, that means it hangs the GUI for 100ms. If the addChip runs in another thread, then it cannot access the GUI in another thread.
How does addChip get called? Is it in response to some other events (such as mouse events)? Please check for GUI event loops. For example, when the data changes, it causes some events (such as scrollbar events). The events causes addChip to be called. addChip changes the data again, and it causes further events in a loop.
In our sample code, when we need to change the chart, instead of calling drawChart directly, our code normally called "myChartViewer.updateViewPort(True, True)", and the drawChart is called in the ViewPortChanged event handler.
Best Regards
Peter Kwan |
Re: Refreshing the data calling my load and draw procedures wont fire in my normal sub |
Posted by Jeff on Jan-20-2025 21:56 |
|
I got it to work.
AddChip routine was being called from another form:
frmAddActivity.ShowDialog()
'called the AddChip like:
frmbalmain.AddChip()
It does call add chip, but there is an error in the drawChart when called this way.
This works:
frmAddActivity.ShowDialog()
'Dataset has been manipulated with frmAddActivity. Now I'm back on the main form:
If ForceRebuild = True Then
ForceRebuild = False
loadData()
drawChart(WinChartViewer1)
Exit Sub
End If |
|