vb.net 确保列表中的最大索引小于列表的大小
我写了下面的一个代码,具体任务是:在DataGridView1里面添加2列作为我下面画图的坐标点,希望能根据DataGridView1里面的数据画出来曲线图,可是每次运行到 qw(t) = DataGridView1.Rows(i).Cells(j).Value这句就会出错,不知道怎么修改,我是初学者,求个人大神帮帮!
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim g As Graphics = Me.CreateGraphics()
Dim mypen As Pen = New Pen(Color.Blue, 2)
Const m As Integer = 100
Const n As Integer = 2
Dim t, k, x As Integer
Dim i, j As Integer
Dim qw(i) As Single
t = 0
For i = 0 To m
For j = 0 To n
qw(t) = DataGridView1.Rows(i).Cells(j).Value
t = t + 1
Next
Next
k = t
For t = 0 To k
g.DrawBezier(mypen, qw(t), qw(t + 1), qw(t + 2), qw(t + 3), qw(t + 4), qw(t + 5), qw(t + 6), qw(t + 7))
t += 8
Next
mypen.Dispose() : g.Dispose()
End Sub 索引 VB.NET DataGridView 画图曲线
[解决办法]
把 qw(t) = DataGridView1.Rows(i).Cells(j).Value换成 qw(t) = DataGridView1.Rows(i).Cells(j).Text可以吗,不知道你前台的 DataGridView1是怎么设置的。
[解决办法]
DataGridView1.Rows(i).Cells(j).Value