VB.NET – All in One → VB.NET DataGridView – Add CheckBox Column – Camposha

VB.NET – All in One

VB.NET – All in One

VB.NET DataGridView – Add CheckBox Column

  • Used with Boolean Checkstate values.
  • When you bind to these values, DataGridViewCheckBoxColumn is generated.
  • Boolean values display as two-state or three-state depending on the value of ThreeState property.
  • With CheckState, the value of ThreeState value is true.

Tools

These are the tools we used:

  • Platform : .NET
  • Language : VB.NET
  • IDE : Visual Studio 2013

Source Code

Lets have a look at the project’s source code.

Form1.cs

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        updateDG()
    End Sub

    Private Sub updateDG()
        'ADD COLUMN
        DataGridView1.ColumnCount = 3
        DataGridView1.Columns(0).Name = "Position"
        DataGridView1.Columns(1).Name = "Team"
        DataGridView1.Columns(2).Name = "Points"

        'ADD ROWS
        Dim row As ArrayList = New ArrayList
        row.Add("1")
        row.Add("Man Utd")
        row.Add("82")
        DataGridView1.Rows.Add(row.ToArray())

        'ADD 2ND ROW
        row = New ArrayList
        row.Add("2")
        row.Add("Man cITY")
        row.Add("80")
        DataGridView1.Rows.Add(row.ToArray())

        'ADD 2ND ROW
        row = New ArrayList
        row.Add("3")
        row.Add("Chelsea")
        row.Add("78")
        DataGridView1.Rows.Add(row.ToArray())

        Dim chk As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn
        chk.HeaderText = "Qualified"
        chk.Name = "check"
        DataGridView1.Columns.Add(chk)

    End Sub

    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick

        If e.ColumnIndex = 3 Then
            MessageBox.Show((e.RowIndex + 1).ToString() + " row selected")
        End If

    End Sub
End Class

More

YouTube

  • Visit our channel for more examples like these.

Facebook

 

Leave a Reply

Your email address will not be published. Required fields are marked *

(1) Comment

  • wittyscot July 11, 2019 @ 4:07 pm

    its good

Comments are closed.

X