How to Select a Cell in a DataGridView

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Email

Knowing how to select a cell in Data Grid View control using Microsoft Visual Basic.NET can make your Windows applications more user-friendly. You use a Grid control to show data in a tabular format similar to a table. You can use it to show small or large amounts of data. VB.NET is an object-oriented computer programming language you can use to create Windows applications. In a few steps, you can create a VB.NET project, and use a Grid control to display data and select an individual cell.

Skill level:

Things you need

  • Microsoft Visual Basic Express

Show MoreHide


  1. 1

    Start Microsoft Visual Basic Express. Click "New Project..." on the left-hand pane of your screen and select "Windows Forms Application." Click "OK."

  2. 2

    Double-click "Button" on the "Toolbox" pane to add a new button control. Double-click "DataGridView" to add a new grid control. Double-click "Button1" to open the "Form1.vb" module.

  3. 3

    Type the following text to define the number of columns and define the column names of the Data Grid View control:

    DataGridView1.ColumnCount = 3

        With DataGridView1
            .RowHeadersVisible = False
            .Columns(0).Name = "Num"
            .Columns(1).Name = "Desc"
            .Columns(2).Name = "Status"
        End With
  4. 4

    Type the following text to load data to the Data Grid View control:

        Dim row 0 As String() = {"0", "monitor", "Sold"}
        Dim row 1 As String() = {"1", "desk", "Sold"}
        With Me.DataGridView1.Rows
        End With
  5. 5

    Type the following text to select the last cell in the second row:

        With Me.DataGridView1.Rows
            .Item(1).Cells(2).Selected = True
        End With
  6. 6

    Press "F5" to run your program and click "Button1" to load data and select the last cell in the second row.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.