I want to make 6 digit number and put it number of count at data grid view 1. Currently I used below code. This show numbers like 1,2,3,4,5..... like....

 For Each row As DataGridViewRow In DataGridView1.Rows
            Dim obj(row.Cells.Count - 1) As Object
            For i = 0 To row.Cells.Count - 1
                obj(i) = row.Cells(i).Value
            Next
            Me.DataGridView3.Rows.Add((obj))
        Next

But I want to >> make numbers like this. 100001,100002,100003 .....
Can anyone help ?

Recommended Answers

All 8 Replies

yes it will add.
if 4 lines available then 4th number should be 100004
if 5 line available then 5th number should be 10005

It looks to me that instead of adding 100000 you should probably use the value of I and add 100001

 For Each row As DataGridViewRow In DataGridView1.Rows
    Dim obj(row.Cells.Count - 1) As Object
    For i = 0 To row.Cells.Count - 1
        obj(i) = i + 100001
    Next
    Me.DataGridView3.Rows.Add((obj))
Next

This will give you the values you say you want.

commented: still same problem. all values are 100001 +0

@tinstaafl sir from your code all shows 100001

See if something like this works:

 For j = 0 to DataGridView1.Rows.Count - 1
    Dim obj(DataGridView1.Rows(j).Cells.Count - 1) As Object
    For i = 0 To row.Cells.Count - 1
        obj(i) = j + 100001
    Next
    Me.DataGridView3.Rows.Add((obj))
Next

@OP

Consider you have 2 for loops in your code. So while line 4 is where you need to add what you want, you have to decide if the value is from the inner, outer for loop plus the 100000 or 100001 or another formula. But line 4 is where you need to code as you wish.

'atleast you have more than 1 row.
'this will put your number in column 0 (1st column).

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

        For j = 0 To DataGridView1.Rows.Count - 2
            DataGridView1(0, j).Value = j + 100001
        Next

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.