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

How to Set the Focus on the DataGridView Cell

Good Day:

I am using VB.NET 2005 and the DataGridView.  When the user does not enter data in cell 0 and row(i); I would like to set the focus to the cell with the missing data.  The following code does not work:
            DataGridView1.Rows(i).Cells(0).Selected = True

My entire code is as follows:
  Private Sub DataGridView1_CellLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave

Dim i As Int32
i = e.RowIndex

        If IsDBNull(DataGridView1.Rows(i).Cells(0).Value) Then
            MsgBox("Need Data!")
            DataGridView1.Rows(i).Cells(0).Selected = True
             End If
    End Sub

Any Suggestions?

Thank You,
Denise
0
DeniseGoodheart
Asked:
DeniseGoodheart
1 Solution
 
vs1784Commented:
Try using this

dataGridView1.CurrentCell = dataGridView1[columnIndex, RowIndex];
0
 
DeniseGoodheartAuthor Commented:
Hello vs1784:

Thanks for your suggestion.  I added a command button called test and put the code behind it.  It works great, but does not work using the DataGridView events.  I will post a new question about this.

Many Thanks,
Denise
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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