我正在尝试更新数据网格视图和图表 我有一个类,在该类中我有一个从数据库返回数据表的函数 我需要bindingSource,因为这是我更新图表(栏)的方式 不幸的是,当图表是Pie时,我需要使用数据表进行更新 因此,当我加载表格时,我有:
gbsGraph.DataSource = graphFunctions.prepareData() 'gbsGraph is a BindingSource
gdtGraphData = graphFunctions.prepareData() 'gdtGraphData isDataTable
gdv.DataSource = gbsGraph 'gdv is my datagridview
AddHandler gdtGraphData.RowChanged, AddressOf gdtGraphData_RowChanged 'add event for update piechart
fillChart()'code to fill the chart
当用户按下刷新按钮时:
Private Sub tsmiRefresh_Click(sender As System.Object, e As System.EventArgs) Handles tsmiRefresh.Click
gbsGraph.DataSource = graphFunctions.prepareData()' this works and dgv and my bar charts are updated
gdtGraphData = graphFunctions.prepareData() 'this is should trigger the event gdtGraphData.RowChanged but it doesn't
End Sub
我的DataRowChange自定义事件:
Private Sub gdtGraphData_RowChanged(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)
'Here is code to refill the Pie chart
'but the event isn't fired
End Sub
所以我的问题是如何更新我的数据表并触发gdtGraphData_RowChanged事件?
由于 Ť
答案 0 :(得分:0)
当更改数据表中的行内的值时,不会在将新数据表实例放入变量时引发行更改事件...
一个例子:
' This will raise the rowchanged event
gdtGraphData.Rows(0)("someField") = 123
' This will not!
gdtGraphData = graphFunctions.prepareData()
您必须将代码放入tsmiRefresh_Click中重新填充饼图......
答案 1 :(得分:0)
在这一行
gdtGraphData = graphFunctions.prepareData()
您正在删除您收听其DataTable
事件的RowChanged
。您必须在现有表中进行更改才能使任何事件触发。
我认为你可以在上面一行之后添加对填充饼图的方法的调用。