Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5427
  • Last Modified:

How to add checkbox in the DataGridview in Vb.Net windows form.

How to add checkbox in front of every record in DataGridview1.
0
searchsanjaysharma
Asked:
searchsanjaysharma
2 Solutions
 
jpaulinoCommented:
You just need to add a DataGridViewCheckBoxColumn() to the datagrid.

Here's an example:

        DataGridView1.ColumnCount = 3
        DataGridView1.Columns(0).Name = "Product ID"
        DataGridView1.Columns(1).Name = "Product Name"
        DataGridView1.Columns(2).Name = "Product_Price"

        Dim row As String() = New String() {"1", "Product 1", "1000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"2", "Product 2", "2000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"3", "Product 3", "3000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"4", "Product 4", "4000"}
        DataGridView1.Rows.Add(row)

        Dim chk As New DataGridViewCheckBoxColumn()
        DataGridView1.Columns.Add(chk)
        chk.HeaderText = "Check Data"
        chk.Name = "chk"
        DataGridView1.Rows(2).Cells(3).Value = True

Open in new window

Source: http://vb.net-informations.com/datagridview/vb.net_datagridview_checkbox.htm

If you are using a datasource and the type of the field is boolean, then it will automatically be defined.
0
 
Mohamed AbowardaSoftware EngineerCommented:
0
 
searchsanjaysharmaAuthor Commented:
ok
0

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