Click here to Skip to main content
12,820,546 members (30,069 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0
I have added like this...
 DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();

                checkColumn.AutoSizeMode =
                checkColumn.CellTemplate = new DataGridViewCheckBoxCell();
                checkColumn.FalseValue = true;
                checkColumn.HeaderText = "SelectCompany";
                checkColumn.Name = "CheckBoxes";
                checkColumn.TrueValue = true;
                checkColumn.FalseValue = false;

But I am not able to check the checkboxes
Posted 21-Jun-12 20:11pm
Updated 21-Jun-12 20:14pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Once you have your data in the grid, you can loop through the rows and check each box like this:
foreach (DataGridViewRow row in dataGridView1.Rows)
        row.Cells[CheckBoxColumn1.Name].Value = true;

The Click event you can get like this:

private void button1_Click(object sender, EventArgs e)
        List<DataGridViewRow> rows_with_checked_column = new List<DataGridViewRow>();
        foreach (DataGridViewRow row in dataGridView1.Rows)
            if (Convert.ToBoolean(row.Cells[CheckBoxColumn1.Name].Value) == true)
        // Do what you want with the check rows

Good example on MSDN[^]
Check out Detailed description[^] here.
Member 9364222 4-Oct-12 6:52am
i have a gridview with a checkbox column,databound column and a textbox template column.Initially the text box column is not visible. when i click the checkbox in a row the corresponding row's text box should be visible.

my gridview
<asp:GridView ID="gvwProduct" OnPageIndexChanging="gridView_PageIndexChanging" runat="server"
AutoGenerateColumns="False" EnableModelValidation="True"
Width="259px" Height="130px"> <%--onselectedindexchanged="gvwProduct_SelectedIndexChanged">--%>
<asp:TemplateField HeaderText="Check" >
<asp:CheckBox ID="chkbxPrd" AutoPostBack="true" runat="server" />

<asp:BoundField DataField="cService_Desc" HeaderText="Product/Service" runat="server" />

<asp:TemplateField HeaderText="Contract Value">
<asp:Label ID="lblPrd" runat="server" Visible="true"/>
<asp:TextBox ID="txtPrd" runat="server" Visible="false" />

is there any solution for this
Chavakorn 19-May-13 8:24am
Sorry I have a question that this Code for Gridview or DataGridview ?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


you can use TemplateFields for the GridView:

                 <asp:GridView ID="GridView1" runat="server">


                        <asp:TemplateField >
                                 <asp:CheckBox ID="myCheckBox" runat="server" />



Hope this helps:)
CHill60 30-Jul-15 6:15am
That's a GridView not a DataGridView - there is a difference. That and the post is over 3 years old

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 30 Jul 2015
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100