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

Posted on 2012-08-31
Last Modified: 2012-09-17
How to add checkbox in front of every record in DataGridview1.
Question by:searchsanjaysharma
    LVL 48

    Assisted Solution

    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"}
            row = New String() {"2", "Product 2", "2000"}
            row = New String() {"3", "Product 3", "3000"}
            row = New String() {"4", "Product 4", "4000"}
            Dim chk As New DataGridViewCheckBoxColumn()
            chk.HeaderText = "Check Data"
            chk.Name = "chk"
            DataGridView1.Rows(2).Cells(3).Value = True

    Open in new window


    If you are using a datasource and the type of the field is boolean, then it will automatically be defined.
    LVL 12

    Accepted Solution


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now