• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3316
  • Last Modified:

Highlight row when cell is clicked in DataGridView contol

I would like the row to be highlighted when a cell is clicked in the DataGridView control.
I am using VB.NET 2005 Express Edition.

The following code was posted on a previous thread in EE, but I must be doing something wrong.
Here is my code:
Private Sub DataGridView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseUp
        Dim pt = New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = DataGridView1.HitTest(pt)

        If hti.Type = DataGrid.HitTestType.Cell Then
            DataGridView1.CurrentCell = New DataGridCell(hti.Row, hti.Column)
        End If

    End Sub
...and here are the errors in the Error List:
Argument not specified for parameter 'y' of 'Public Function HitTest(x As Integer, y As Integer) As System.Windows.Forms.DataGridView.HitTestInfo'.
Value of type 'System.Windows.Forms.DataGridCell' cannot be converted to 'System.Windows.Forms.DataGridViewCell'.
Overload resolution failed because no accessible 'Select' accepts this number of arguments.

Does the fact that I am using VB Express 2005 have anything to do with this? Maybe I need to Import a new Namespace in code? I have many namespaces checked in Project Properties, but in code I am only importing:
Imports System.Data
Imports System.Data.OleDb

Any help would be great. Thanks!
1 Solution
stltodaycomAuthor Commented:
This did the trick.
I put this code in the Form1_Load event:

With Me.DataGridView1
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
End With
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now