Henry Gathigira Henry Gathigira - 1 year ago 118
Vb.net Question

How to display rowcount in a textbox in vb.net

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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download