0

i have datagridview contains more than 100 rows: student name, class and code, i want to get on 3 sequences student codes when select any row to show them in 3 textboxes, whatever the position of the row which i selected.

Dim I As Integer = 0
Dim code1 As String = DataGridView1.SelectedRows(I).Cells(1).Value.ToString
TextBox1.Text = code1

Dim code2 As String = DataGridView1.SelectedRows(I + 1).Cells(1).Value.ToString
TextBox2.Text = code2

Dim code3 As String = DataGridView1.SelectedRows(I + 2).Cells(1).Value.ToString
TextBox3.Text = code3

i tried to solve it but it's Error

3
  • Are you certain there are 3 selected rows? What is the error and on which line is it occurring? Commented Jul 31, 2023 at 10:19
  • in fact i did select one row only, is should to select the 3 rows together? Commented Jul 31, 2023 at 12:29
  • 1
    Based on your code you'd have to have selected 3 rows. I think you'd actually like to look at the single selected row, and the two subsequent rows. Change your code to get the index of the selected row, and then look at the next rows in the collection. Commented Jul 31, 2023 at 16:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.