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 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 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
0 OriginalGriff 495
1 Maciej Los 205
2 Suvendu Shekhar Giri 159
3 Richard Deeming 140
4 Kornfeld Eliyahu Peter 133
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,895
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,333
4 Maciej Los 2,561


Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 17 Dec 2013
Copyright © CodeProject, 1999-2015
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