Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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 19:11pm
Edited 21-Jun-12 19: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 at 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 at 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 2

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 695
1 OriginalGriff 518
2 Abhinav S 313
3 thatraja 245
4 CPallini 130
0 Sergey Alexandrovich Kryukov 8,372
1 OriginalGriff 4,830
2 Peter Leow 3,784
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 17 Dec 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid