Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have a study about passing datagird values to devexpress chartcontrol. I have X and Y values in my gridcontrol.(It can have different row count) I would like to use for next loop due to different point counts.(needs to stop after last value) Sometimes I have 5 values, sometimes 8, ,12,..etc. I use code below, but not achived , maybe there is a differet code.

What I have tried:

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
Posted
Updated 27-Mar-17 2:45am
Comments
Ralf Meier 27-Mar-17 6:11am    
This code doesn't look wrong - so where is your Problem ...?

1 solution

here to find correct code, solved problem, need to check for new row before adding the values from current row to your chart. To do this you can use the 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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900