[RESOLVED] Datagridview --> loop or array?
Hi,
I would like to fill the first row of my datagridview with the values “0.02” to “0.20”. Cause there are “only” 10 rows it can be done like this
Code:
DataGridView1.RowCount = 10
DataGridView1.Rows(0).Cells(0).Value = "0.02"
DataGridView1.Rows(1).Cells(0).Value = "0.04"
DataGridView1.Rows(2).Cells(0).Value = "0.06"
DataGridView1.Rows(3).Cells(0).Value = "0.08"
DataGridView1.Rows(4).Cells(0).Value = "0.10"
DataGridView1.Rows(5).Cells(0).Value = "0.12"
DataGridView1.Rows(6).Cells(0).Value = "0.14"
DataGridView1.Rows(7).Cells(0).Value = "0.16"
DataGridView1.Rows(8).Cells(0).Value = "0.18"
DataGridView1.Rows(9).Cells(0).Value = "0.20"
but in case there are more (i.e. 150) it’s way to complicated. Is there an easier way (like a loop or an array)?
The other rows will be filled later with different variables and stuff
Cheers
Moritz
Re: Datagridview --> loop or array?
Here is an idea for you, I don't have access to VS at the moment but this should work.
Code:
Dim Value As Double = 0.02 ' Starting Value
Dim IncreaseValue As Double = 0.02 ' Value to increase by
For i As Integer = 0 To 10
DataGridView1.Rows.Add(Value.ToString("0.00"))
Value += IncreaseValue
Next
Re: Datagridview --> loop or array?
working great, just had to change "0 To 9" because "0" is equal 0.02.
Thanks :)