【问题标题】:VB.net datagridview to chart control devexpressVB.net datagridview 到图表控件 devexpress
【发布时间】:2017-08-19 20:54:54
【问题描述】:

我有一项关于将 DataGridView 值传递给 DevExpress ChartControl 的研究。我的 DataGridView 中有 X 和 Y 值(它可以有不同的行数)。由于点数不同(需要在最后一个值之后停止),我想使用 for next 循环。有时我有 5 个值,有时是 8、12 等。我使用以下代码:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim i As Integer

    For i = 0 To DataGridView1.Rows.Count - 1

        ChartControl1.Series("Series 1").Points.Add(New SeriesPoint(DataGridView1.Item(0, i).Value, DataGridView1.Item(1, i).Value))
    Next

End Sub

另见图片:

【问题讨论】:

    标签: vb.net datagrid devexpress


    【解决方案1】:

    DataGridView 中有新行。在将当前行的值添加到图表之前,您需要检查新行。为此,您可以使用 DataGridView.NewRowIndex 属性。
    示例如下:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
        Dim i As Integer
    
        For i = 0 To DataGridView1.Rows.Count - 1
            If i <> DataGridView1.NewRowIndex Then
                ChartControl1.Series("Series 1").Points.Add(New SeriesPoint(DataGridView1.Item(0, i).Value, DataGridView1.Item(1, i).Value))
            End If
        Next
    
    End Sub
    

    【讨论】:

    • 非常感谢 nempoBu4,现在可以正常工作了。
    猜你喜欢
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-09
    相关资源
    最近更新 更多