there is no row at position 0

uls123

Member
Joined
Mar 14, 2013
Messages
7
Programming Experience
Beginner
hello,
i wrote a code for when i select a row in the datagridview, the columns values appears in every related text box but everytime i try to click the mouse on a row an error occurs saying that "there is no row at position 0".
code:
Imports System.Data.SqlClient
Public Class Professor Dim inc As Integer
Dim tt As New DataTable
Dim r As DataRow
Private Sub DataGridView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseUp
Dim rc As Integer
rc = DataGridView1.CurrentRow.Index
inc = rc
getprof(rc)
End Sub
Public Sub getprof(ByVal i As Integer)
r = tt.Rows(i)
prof_lname.Text = r("nom_prof")
prof_fname.Text = r("prenom_prof")
prof_birthdate.Text = r("datenaiss_prof")
prof_email.Text = r("email_prof")
prof_telephone.Text = r("numtel_prof")
prof_username.Text = r("username")
prof_password.Text = r("password")
prof_nationalite.Text = r("nationalite")
prof_gender.Text = r("desc_sexe")
prof_address.Text = r("address_prof")
End Sub
End Class

thank you in advance.
 
Are you actually binding that DataTable to the DataGridView? If not then are you adding rows to the DataTable manually? The error would suggest that the answers are "no" and "no". If you were binding then there would be no need for any code at all to populate some TextBoxes but, regardless, you should absolutely not be handling the MouseUp event of the DataGridView.
 
there are some data showing in the data grid but i can't seem to manage clicking on a row and viewing the different columns in the corresponding text boxes; the MouseUp event is not working.
 
there are some data showing in the data grid but i can't seem to manage clicking on a row and viewing the different columns in the corresponding text boxes;
Yeah, great. Now maybe you could actually provide the information that I asked for.
the MouseUp event is not working.
That probably explains why I said that you shouldn't be using it.
 
Then what event would you suggest i do? Sorry for my repetitive questions, but i need to solve it in some way.
 
This may surprise you but I did not ask you questions in post #2 for fun. I asked those questions because I need that information to help you with your problem. I will give you one more chance to answer them and then I'll lose interest altogether.
 
Back
Top