Click here to Skip to main content
12,246,032 members (42,944 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 =
                   DataGridViewAutoSizeColumnMode.DisplayedCells;
               checkColumn.CellTemplate = new DataGridViewCheckBoxCell();
               checkColumn.FalseValue = true;
               checkColumn.HeaderText = "SelectCompany";
               checkColumn.Name = "CheckBoxes";
               checkColumn.TrueValue = true;
               checkColumn.FalseValue = false;
               dgvGetCompanyDetails.Columns.Add(checkColumn);
But I am not able to check the checkboxes
Posted 21-Jun-12 20:11pm
Edited 21-Jun-12 20:14pm
v2
Rate this: bad
 
good
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)
            {
                rows_with_checked_column.Add(row);
            }
        }
        // Do what you want with the check rows
    }

Refer:
Good example on MSDN[^]
Check out Detailed description[^] here.
  Permalink  
Comments
Member 9364222 4-Oct-12 6:52am
   
hi,
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
 
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
you can use TemplateFields for the GridView:
 
                 <asp:GridView ID="GridView1" runat="server">
 
                   <Columns>
 
                        <asp:TemplateField >
                             <ItemTemplate>
                                 <asp:CheckBox ID="myCheckBox" runat="server" />
                             </ItemTemplate>
                         </asp:TemplateField>
 
                  </Columns>
 
               </asp:GridView>
 

 
Hope this helps:)
  Permalink  
Comments
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.160426.1 | Last Updated 30 Jul 2015
Copyright © CodeProject, 1999-2016
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