Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the example of what I want to do, but I can't

Sample Image[^]

That image shows 6 textboxes and the data came from a datagridview. The problem is when I use
VB
For i = 0 To dgv.Rows.Count-1
Tb1.text = DGV.Item(1, i).Value
Tb2.text = DGV.Item(1, i).Value
Tb3.text = DGV.Item(1, i).Value
Tb4.text = DGV.Item(1, i).Value
Tb5.text = DGV.Item(1, i).Value
Tb6.text = DGV.Item(1, i).Value
Next i 


it only shows the first row of the datagridview. Thanks in advance.

What I have tried:

VB
For i = 0 To dgv.Rows.Count-1
Tb1.text = DGV.Item(1, i).Value
Tb2.text = DGV.Item(1, i+1).Value
Tb3.text = DGV.Item(1, i+2).Value
Tb4.text = DGV.Item(1, i+3).Value
Tb5.text = DGV.Item(1, i+4).Value
Tb6.text = DGV.Item(1, i+5).Value
Next i 


but when I press for the next content 6 set, it just jumps.
Posted
Updated 19-Oct-22 22:38pm

You need to get the six different rows each loop, and the loop count needs to increase by 6 each time:
VB
For i = 0 To dgv.Rows.Count-1 Step 6
    Tb1.text = DGV.Item(1, i).Value
    Tb2.text = DGV.Item(1, i+1).Value
    Tb3.text = DGV.Item(1, i+2).Value
    Tb4.text = DGV.Item(1, i+3).Value
    Tb5.text = DGV.Item(1, i+4).Value
    Tb6.text = DGV.Item(1, i+5).Value
Next i 
 
Share this answer
 
Comments
razrx 20-Oct-22 21:00pm    
oooh, now I know how to use 'step'. Thank you so much.
To add to what Richard has said, you probably need to rethink this completely: A text box only shows one value, so the loop around the assignment will mean that only the final iteration will show any data as each time you go around the loop you will overwrite the text box content that the previous iteration set.

If you want to show multiple rows worth of data at all, you probably don't want a TextBox.
If you want a single row of data, you don't want a loop at all.
 
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