0

I am using Textbox1.Text = DataGridView1.RowCount() to display(in Textbox1) the total number of items in the datagridview on my vb.net app. Now i want Textbox2 to display the position at the datagridview. How will i do that? Eg I want something like 6 out of 50. So "6" will be displayed at Textbox1. Are you getting me?

Henry Gathigira
  • 265
  • 4
  • 11

3 Answers3

1

You should handle that in the below event

Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged   
    If dgv.CurrentRow isnot Nothing
       Textbox1.Text = dgv.CurrentRow.Index + 1
    End If
End Sub
Ed_
  • 973
  • 11
  • 25
  • this is working but 1. It seems its starting to count from zero and i would like it to start counting at one. 2. I wish this could be shown in a textbox instead of a messagebox. Kindly assist. – Henry Gathigira May 17 '16 at 21:35
  • @HenryGathigira I updated the code; in programming the count usually starts from 0 – Ed_ May 17 '16 at 21:37
  • Awsome. You are the Best. And a genius too. That's what I wanted. – Henry Gathigira May 17 '16 at 21:41
0
For i As Integer = 0 To DataGridView1.RowCount

    i = +i

    Textbox1.Text = i

Next
Jason Tyler
  • 1,331
  • 13
  • 26
-1

Use DataGridView.CurrentRow.Index property.

dotNET
  • 33,414
  • 24
  • 162
  • 251
  • Object reference not set to an instance of an object. That's the error am getting. – Henry Gathigira May 17 '16 at 20:42
  • 1
    Use `If` to check if `CurrentRow` is `null`. Come on. That is pretty basic. – dotNET May 17 '16 at 20:44
  • Yeah I know its basic but i am also so new in vb. Did somebody get my question? If code 1 is working i know code 2 can work too. Somebody just assist. I am pretty tired. In other words i want the code behind binding navigator "position" textbox. – Henry Gathigira May 17 '16 at 20:50