Error on DataGridView1 Double Click event

I'm trying to populate several textboxes by clicking on a row in the datagrid with the following code below, but I'm getting the following error:

Argument not specified for parameter 'y' of 'Public Function HitTest(x As Integer, y As Integer) As System.Windows.Forms.DataGridView.HitTestInfo'.

Can this be done with DataGridView1_CellContentClick also, instead of DoubleClick and how would it be coded??

thanks
Private Sub DataGridview1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
 
        Dim pt As System.Drawing.Point = DataGridView1.PointToClient(Cursor.Position)
        Dim hti As DataGrid.HitTestInfo = Me.DataGridView1.HitTest(pt)
 
        If hti.Type = DataGrid.HitTestType.Cell Then
            TextBox2.Text = CType(myDataSet.Tables(0).Rows(hti.Row).Item("Last_Name"), String)
            TextBox3.Text = CType(myDataSet.Tables(0).Rows(hti.Row).Item("First_Name"), String)
            TextBox4.Text = CType(myDataSet.Tables(0).Rows(hti.Row).Item("Home_Phone"), String)
            TextBox5.Text = CType(myDataSet.Tables(0).Rows(hti.Row).Item("Cell_Phone"), String)
            TextBox6.Text = CType(myDataSet.Tables(0).Rows(hti.Row).Item("Pager_No"), String)
            TextBox7.Text = CType(myDataSet.Tables(0).Rows(hti.Row).Item("Other_Info"), String)
        End If
 End Sub

Open in new window

LVL 2
Richard KreidlSoftware DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge PaulinoIT Pro/DeveloperCommented:
What you want to do with that ?
0
Richard KreidlSoftware DeveloperAuthor Commented:
I basically want to user to click on any row and populate several textboxes with the data within that row.
0
Jorge PaulinoIT Pro/DeveloperCommented:
Why don't you use RowEnter event and replace hti.Row with e.RowIndex ?
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        ' your code
    End Sub

Open in new window

0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Richard KreidlSoftware DeveloperAuthor Commented:
Here's the code:

Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        Dim pt As System.Drawing.Point = DataGridView1.PointToClient(Cursor.Position)
        Dim hti As DataGrid.HitTestInfo = DataGridView1.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            TextBox2.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Last_Name"), String)
            TextBox3.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("First_Name"), String)
            TextBox4.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Home_Phone"), String)
            TextBox5.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Cell_Phone"), String)
            TextBox6.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Pager_No"), String)
            TextBox7.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Other_Info"), String)
        End If
    End Sub

Still getting this error:
Argument not specified for parameter 'y' of 'Public Function HitTest(x As Integer, y As Integer) As System.Windows.Forms.DataGridView.HitTestInfo'.
 
with this line:
Dim hti As DataGrid.HitTestInfo = DataGridView1.HitTest(pt)
0
Jorge PaulinoIT Pro/DeveloperCommented:
You don't need HitTest ... e.RowIndex gives you the row index.
Try this way

Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
            TextBox2.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Last_Name"), String)
            TextBox3.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("First_Name"), String)
            TextBox4.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Home_Phone"), String)
            TextBox5.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Cell_Phone"), String)
            TextBox6.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Pager_No"), String)
            TextBox7.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Other_Info"), String)
    End Sub

Open in new window

0
Richard KreidlSoftware DeveloperAuthor Commented:
I'm getting an error on execution. I attached a screen print of the  error.
screen-print-error.png
0
Richard KreidlSoftware DeveloperAuthor Commented:
This is my code;
Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        TextBox2.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Last_Name"), String)
        TextBox3.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("First_Name"), String)
        TextBox4.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Home_Phone"), String)
        TextBox5.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Cell_Phone"), String)
        TextBox6.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Pager_No"), String)
        TextBox7.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Other_Info"), String)
    End Sub
0
Jorge PaulinoIT Pro/DeveloperCommented:
That's in the datagridview load ?
0
Richard KreidlSoftware DeveloperAuthor Commented:
I uncommented your code and it doesn't giove me an error.

I'll attached the whole code here.
Option Explicit On
 
Imports System.Data.OleDb
Imports System.IO
Imports System.Text
Imports Microsoft.Win32
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Public Class Form1
    Private adapter As OleDbDataAdapter
    Private myDataSet As DataSet
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Update_Database()
    End Sub
    Sub Update_Database()
        Dim myBindingSource As New BindingSource
        Dim sSQL As String = "SELECT * FROM PhoneInfo"
        Dim cmd As OleDbCommand = New OleDbCommand(sSQL, conn)
        adapter = New OleDbDataAdapter(cmd)
        myDataSet = New DataSet
        adapter.Fill(myDataSet)
        myBindingSource.DataSource = myDataSet.Tables(0).DefaultView
        DataGridView1.DataSource = myBindingSource
    End Sub
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        TextBox2.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Last_Name"), String)
        TextBox3.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("First_Name"), String)
        TextBox4.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Home_Phone"), String)
        TextBox5.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Cell_Phone"), String)
        TextBox6.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Pager_No"), String)
        TextBox7.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Other_Info"), String)
    End Sub
End Class

Open in new window

0
Richard KreidlSoftware DeveloperAuthor Commented:
I meant when I comment out your code it doesn't give me an error. Sorry about the typo.
0
Jorge PaulinoIT Pro/DeveloperCommented:
Try this way:
Option Explicit On
 
Imports System.Data.OleDb
Imports System.IO
Imports System.Text
Imports Microsoft.Win32
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Public Class Form1
    Private adapter As OleDbDataAdapter
    Private myDataSet As DataSet
    Private loadComplete As Boolean
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Update_Database()
        loadComplete = True
    End Sub
    Sub Update_Database()
        Dim myBindingSource As New BindingSource
        Dim sSQL As String = "SELECT * FROM PhoneInfo"
        Dim cmd As OleDbCommand = New OleDbCommand(sSQL, conn)
        adapter = New OleDbDataAdapter(cmd)
        myDataSet = New DataSet
        adapter.Fill(myDataSet)
        myBindingSource.DataSource = myDataSet.Tables(0).DefaultView
        DataGridView1.DataSource = myBindingSource
    End Sub
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter 
        If loadComplete Then
        TextBox2.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Last_Name"), String)
        TextBox3.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("First_Name"), String)
        TextBox4.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Home_Phone"), String)
        TextBox5.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Cell_Phone"), String)
        TextBox6.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Pager_No"), String)
        TextBox7.Text = CType(myDataSet.Tables(0).Rows(e.RowIndex).Item("Other_Info"), String)
        End If
    End Sub
End Class

Open in new window

0
Richard KreidlSoftware DeveloperAuthor Commented:
Same error as before.

Just a thought, I've seen other examples that use DoubleClick and CellContentClick for DataGridView1 event handlers, isn't that another option to use??
0
Jorge PaulinoIT Pro/DeveloperCommented:
What error do you got ?
0
Richard KreidlSoftware DeveloperAuthor Commented:
screen print attached.
screen-print.png
0
Jorge PaulinoIT Pro/DeveloperCommented:
Ok, small change
If e.RowIndex <> -1 AndAlso loadComplete Then
   Me.TextBox2.Text = Me.DataGridView1("Last_Name", e.RowIndex).Value.ToString
   '  fill the others
End If

Open in new window

0
Richard KreidlSoftware DeveloperAuthor Commented:
I'm getting a different error that column: Last_Name can't be found.

Attached screen print.

That's weird!! That column exists. It's not even loading the datagrid.
screen-print.png
0
Jorge PaulinoIT Pro/DeveloperCommented:
Try to replace the name with 0 and show me the code now.
0
Richard KreidlSoftware DeveloperAuthor Commented:
Ok here's the code

 Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        If e.RowIndex <> -1 AndAlso loadComplete Then
            Me.TextBox2.Text = Me.DataGridView1(0, e.RowIndex).Value.ToString
         '   Me.TextBox3.Text = Me.DataGridView1(1, e.RowIndex).Value.ToString
         '   Me.TextBox4.Text = Me.DataGridView1(2, e.RowIndex).Value.ToString
         '   Me.TextBox5.Text = Me.DataGridView1(3, e.RowIndex).Value.ToString
         '   Me.TextBox6.Text = Me.DataGridView1(4, e.RowIndex).Value.ToString
         '   Me.TextBox7.Text = Me.DataGridView1(5, e.RowIndex).Value.ToString
        End If
    End Sub

It puts the last name in textbox2, but if I uncomment the other statements it gives me this error:
screen-print.png
0
Jorge PaulinoIT Pro/DeveloperCommented:
Remove the .ToString
 Use only Me.DataGridView1(0, e.RowIndex).Value
0
Richard KreidlSoftware DeveloperAuthor Commented:
Old error. Attached screen print.
screen-print.png
0
Jorge PaulinoIT Pro/DeveloperCommented:
Humm you're using a bindingSource ... you could do that more easy!
 After fill the grid do something like this and define the Dim myBindingSource As New BindingSource outside the update sub.
        Me.TextBox1.DataBindings.Add("Text", myBindingSource , "Last_Name", True)
        Me.TextBox2.DataBindings.Add("Text", myBindingSource , "First_Name", True)

 
0
Richard KreidlSoftware DeveloperAuthor Commented:
New error attached.

also here's my code.
Option Explicit On
 
Imports System.Data.OleDb
Imports System.IO
Imports System.Text
Imports Microsoft.Win32
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Public Class Form1
    Private adapter As OleDbDataAdapter
    Private myDataSet As DataSet
    Private loadComplete As Boolean
    Dim myBindingSource As New BindingSource
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Update_Database()
        loadComplete = True
    End Sub
    Sub Update_Database()
        Dim myBindingSource As New BindingSource
        Dim sSQL As String = "SELECT * FROM PhoneInfo"
        Dim cmd As OleDbCommand = New OleDbCommand(sSQL, conn)
        adapter = New OleDbDataAdapter(cmd)
        myDataSet = New DataSet
        adapter.Fill(myDataSet)
        myBindingSource.DataSource = myDataSet.Tables(0).DefaultView
        DataGridView1.DataSource = myBindingSource
    End Sub
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        If e.RowIndex <> -1 AndAlso loadComplete Then
            Me.TextBox2.DataBindings.Add("Text", myBindingSource, "Last_Name", True)
            Me.TextBox3.DataBindings.Add("Text", myBindingSource, "First_Name", True)
            Me.TextBox4.DataBindings.Add("Text", myBindingSource, "Home_Phone", True)
            Me.TextBox5.DataBindings.Add("Text", myBindingSource, "Cell_Phone", True)
            Me.TextBox6.DataBindings.Add("Text", myBindingSource, "Pager_no", True)
            Me.TextBox7.DataBindings.Add("Text", myBindingSource, "Other_Info", True)
  End If
    End Sub

Open in new window

screen-print.png
0
Richard KreidlSoftware DeveloperAuthor Commented:
going out for awhile. Will check email later..

Thanks for helpinig me on this problem.
0
Jorge PaulinoIT Pro/DeveloperCommented:
You need to remove the Dim myBindingSource As New BindingSource inside the Sub Update_Database()
You will only stay with one declaration in the top of the form
         
0
Richard KreidlSoftware DeveloperAuthor Commented:
Different error. Screen print attached.
My code:
Option Explicit On
 
Imports System.Data.OleDb
Imports System.IO
Imports System.Text
Imports Microsoft.Win32
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Public Class Form1
    Private adapter As OleDbDataAdapter
    Private myDataSet As DataSet
    Private loadComplete As Boolean
    Dim myBindingSource As New BindingSource
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Update_Database()
        loadComplete = True
    End Sub
    Sub Update_Database()
        Dim sSQL As String = "SELECT * FROM PhoneInfo"
        Dim cmd As OleDbCommand = New OleDbCommand(sSQL, conn)
        adapter = New OleDbDataAdapter(cmd)
        myDataSet = New DataSet
        adapter.Fill(myDataSet)
        myBindingSource.DataSource = myDataSet.Tables(0).DefaultView
        DataGridView1.DataSource = myBindingSource
    End Sub
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        If e.RowIndex <> -1 AndAlso loadComplete Then
            Me.TextBox2.DataBindings.Add("Text", myBindingSource, "Last_Name", True)
            Me.TextBox3.DataBindings.Add("Text", myBindingSource, "First_Name", True)
            Me.TextBox4.DataBindings.Add("Text", myBindingSource, "Home_Phone", True)
            Me.TextBox5.DataBindings.Add("Text", myBindingSource, "Cell_Phone", True)
            Me.TextBox6.DataBindings.Add("Text", myBindingSource, "Pager_no", True)
            Me.TextBox7.DataBindings.Add("Text", myBindingSource, "Other_Info", True)        
  End If
    End Sub

Open in new window

screen-print.png
0
Jorge PaulinoIT Pro/DeveloperCommented:
Today is a bad day ... I only see an error at a time :(
Change:
DataGridView1.DataSource = myBindingSource
To:
DataGridView1.DataSource = myDataSet.Tables(0).DefaultView
 
If it doesn't work can you show me the application ?
0
Richard KreidlSoftware DeveloperAuthor Commented:
same error as the last posting screen print.

I've just starting building this application and here's all the code with your changes.
Option Explicit On
 
Imports System.Data.OleDb
Imports System.IO
Imports System.Text
Imports Microsoft.Win32
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Public Class Form1
    Private adapter As OleDbDataAdapter
    Private myDataSet As DataSet
    Private loadComplete As Boolean
    Dim myBindingSource As New BindingSource
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Update_Database()
        loadComplete = True
    End Sub
    Sub Update_Database()
        Dim sSQL As String = "SELECT * FROM PhoneInfo"
        Dim cmd As OleDbCommand = New OleDbCommand(sSQL, conn)
        adapter = New OleDbDataAdapter(cmd)
        myDataSet = New DataSet
        adapter.Fill(myDataSet)
        myBindingSource.DataSource = myDataSet.Tables(0).DefaultView
        DataGridView1.DataSource = myDataSet.Tables(0).DefaultView
End Sub
    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        If e.RowIndex <> -1 AndAlso loadComplete Then
            Me.TextBox2.DataBindings.Add("Text", myBindingSource, "Last_Name", True)
            Me.TextBox3.DataBindings.Add("Text", myBindingSource, "First_Name", True)
            Me.TextBox4.DataBindings.Add("Text", myBindingSource, "Home_Phone", True)
            Me.TextBox5.DataBindings.Add("Text", myBindingSource, "Cell_Phone", True)
            Me.TextBox6.DataBindings.Add("Text", myBindingSource, "Pager_no", True)
            Me.TextBox7.DataBindings.Add("Text", myBindingSource, "Other_Info", True)
      End If
  End Sub

Open in new window

0
Jorge PaulinoIT Pro/DeveloperCommented:
This way should work ...
Option Explicit On
 
Imports System.Data.OleDb
Imports System.IO
Imports System.Text
Imports Microsoft.Win32
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Public Class Form1
 
    Private adapter As OleDbDataAdapter
    Private myDataSet As DataSet
    Private myBindingSource As New BindingSource
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Update_Database()
    End Sub
 
    Sub Update_Database()
        Dim sSQL As String = "SELECT * FROM PhoneInfo"
        Dim cmd As OleDbCommand = New OleDbCommand(sSQL, conn)
        adapter = New OleDbDataAdapter(cmd)
        myDataSet = New DataSet
        adapter.Fill(myDataSet)
        myBindingSource.DataSource = myDataSet.Tables(0).DefaultView
 
        Me.TextBox2.DataBindings.Add("Text", myBindingSource, "Last_Name", True)
        Me.TextBox3.DataBindings.Add("Text", myBindingSource, "First_Name", True)
        Me.TextBox4.DataBindings.Add("Text", myBindingSource, "Home_Phone", True)
        Me.TextBox5.DataBindings.Add("Text", myBindingSource, "Cell_Phone", True)
        Me.TextBox6.DataBindings.Add("Text", myBindingSource, "Pager_no", True)
        Me.TextBox7.DataBindings.Add("Text", myBindingSource, "Other_Info", True)
 
        DataGridView1.DataSource = myBindingSource
    End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KreidlSoftware DeveloperAuthor Commented:
Thanks for all the help. It works!!!
0
Jorge PaulinoIT Pro/DeveloperCommented:
Sorry for all the mess ... I really need to sleep!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.