Listview项目或子项目onchange事件

时间:2012-07-14 09:37:22

标签: vb.net charts controls

当我有一个包含46个项目的列表视图,其中每个项目有4个子项目时,子项目的值随时间变化,当选择列表视图中的项目时,我使用子项目的值绘制饼图使用此代码:

Chart1.Series("Series1").ChartType = SeriesChartType.Pie
Chart1.Series("Series1").Points.Clear()

If ListView3.FocusedItem.SubItems(1).Text > 0 Then
    Chart1.Series("Series1").Points.AddY(ListView3.FocusedItem.SubItems(1).Text)
End If
If ListView3.FocusedItem.SubItems(2).Text > 0 Then
    Chart1.Series("Series1").Points.AddY(ListView3.FocusedItem.SubItems(2).Text)
End If
If ListView3.FocusedItem.SubItems(3).Text > 0 Then
    Chart1.Series("Series1").Points.AddY(ListView3.FocusedItem.SubItems(3).Text)
End If
If ListView3.FocusedItem.SubItems(4).Text > 0 Then
    Chart1.Series("Series1").Points.AddY(ListView3.FocusedItem.SubItems(4).Text)
End If

有没有办法检测子项的值的变化?与文本框中的onchange事件类似,但对于项目或子项目,因为我希望饼图在子项值更改时更新。 此代码更改子项

For xx As Integer = 0 To ListView3.Items.Count - 1
                If ListView3.Items(xx).SubItems(0).Text = googleXMLdocument...<s:name>(j).Value Then

                    If j + 1 = 1 Then
                        ListView3.Items(xx).SubItems(1).Text += 1

                    End If
                    If j + 1 = 2 Then
                        ListView3.Items(xx).SubItems(2).Text += 1
                    End If
                    If j + 1 = 3 Then
                        ListView3.Items(xx).SubItems(3).Text += 1
                    End If
                    If j + 1 > 4 Then
                        ListView3.Items(xx).SubItems(4).Text += 1
                    End If
                End If

            Next

1 个答案:

答案 0 :(得分:1)

试试这段代码。这样,如果子项目发生任何变化,图表将自动更新。你不需要计时器。

For xx As Integer = 0 To ListView3.Items.Count - 1
    If ListView3.Items(xx).SubItems(0).Text = googleXMLdocument...<s:name>(j).Value Then
        If j + 1 = 1 Then
            ListView3.Items(xx).SubItems(1).Text += 1
        End If
        If j + 1 = 2 Then
            ListView3.Items(xx).SubItems(2).Text += 1
        End If
        If j + 1 = 3 Then
            ListView3.Items(xx).SubItems(3).Text += 1
        End If
        If j + 1 > 4 Then
            ListView3.Items(xx).SubItems(4).Text += 1
        End If
    End If
Next

将上面的代码放在循环中。您也可以取消FocusedItem

Chart1.Series("Series1").Points.Clear()

Chart1.Series("Series1").Points.AddY (ListView3.FocusedItem.SubItems(1).Text)
Chart1.Series("Series1").Points.AddY (ListView3.FocusedItem.SubItems(2).Text)
Chart1.Series("Series1").Points.AddY (ListView3.FocusedItem.SubItems(3).Text)
Chart1.Series("Series1").Points.AddY (ListView3.FocusedItem.SubItems(4).Text)
相关问题