.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

CheckBox in datagridview

Posted By: Sanjay Kumar     Posted Date: April 16, 2009    Points:2   Category :Windows Application
Hi I want to use checkboxes with headercheckbox in datagridview so that user can select/deselect all records at single click. Also user should be able to randomly select records. If not all records are selected then headercheckbox should remain unchecked. If all records are checked individually then the headercheckbox should get checked automatically. .net window application with C#.

Responses
Author: Athira Sreejith             
Posted Date: April 16, 2009     Points: 5   

Hi..

<asp:TemplateField HeaderText="Approved" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:CheckBox ID="chkCheckAll" runat="server" AutoPostBack="true" EnableViewState="true"
OnCheckedChanged="chkCheckAll_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkApproval" AutoPostBack="true" runat="server" OnCheckedChanged="chkApproval_CheckedChanged1"
Checked='<%# Bind("IsApproval") %>' />
</ItemTemplate>
</asp:TemplateField>

.csPage:
protected void chkCheckAll_CheckedChanged(object sender, EventArgs e)
{
int iCount = 0;
CheckBox chkCheckAll = (CheckBox)sender;
Boolean status = false;
Boolean flag = false;
if (chkCheckAll.Checked == true)
{
foreach (GridViewRow gvr in gvLeaveApproval.Rows)
{
CheckBox chkApprove = (CheckBox)gvr.FindControl("chkApproval");
chkApprove.Checked = true;

}
}
else
{
CheckBox chkApprove = (CheckBox)gvr.FindControl("chkApproval");
chkApprove.Checked = true;

}
}

private void GetCheckallValue()
{
string sValue = string.Empty;
CheckBox chkAll = new CheckBox();
foreach (GridViewRow gvr in gvLeaveApproval.Rows)
{
CheckBox chkApprove = (CheckBox)gvr.FindControl("chkApproval");
if (chkApprove != null)
{
chkAll = (CheckBox)gvLeaveApproval.HeaderRow.Cells[6].FindControl("chkCheckAll");
if (sValue == "")
{
sValue = chkApprove.Checked.ToString();
}
else
{
sValue = sValue + "," + chkApprove.Checked.ToString();
}
}
}
if (sValue.Contains("False"))
{
if (chkAll != null)
{
chkAll.Checked = false;
}
}
else
{
if (chkAll != null)
{
chkAll.Checked = true;
}
}
}

Author: Sanjay Kumar             
Posted Date: April 16, 2009     Points: 5   

Thanks for the prompt response but u have answered keeping in mind GridView of ASP .net which can easily be done with Java Script. But y requirement is for DataGridView in .net Window Application not web application.
Regards,

Author: Sanjay Kumar             
Posted Date: April 16, 2009     Points: 5   

Thanks for the prompt response but u have answered keeping in mind GridView of ASP .net which can easily be done with Java Script. But y requirement is for DataGridView in .net Window Application not web application.
Regards,

Author: Sanjay Kumar             
Posted Date: April 16, 2009     Points: 5   

Thanks for the prompt response but u have answered keeping in mind GridView of ASP .net which can easily be done with Java Script. But y requirement is for DataGridView in .net Window Application not web application.
Regards,

Author: Praveen             
Posted Date: April 16, 2009     Points: 5   

Hi,
Check out this article for adding checkbox inside datagridview in windows application.

http://dotnetspark.com/kb/151-add-checkbox-inside-datagridview-windows.aspx

Author: Praveen             
Posted Date: April 19, 2009     Points: 5   

Hi Sanjay,
Check out this link this might be helpful to you

http://www.codeproject.com/KB/grid/CheckBoxHeaderCell.aspx

Author: Sanjay Kumar             
Posted Date: April 19, 2009     Points: 5   

Thanks Praveen,
I had gone through that article previously It doesn't serve the purpose also its a bit clumsy, However I have done it in much easier way but that has some limitations thats why I saked for it on the forum.

Author: krishana singh             
Posted Date: December 09, 2010     Points: 5   

using window application

so daragridview item collection in which set coloumntype

DatagridviewCheckboxcolumn



Author: Clintonzz             
Posted Date: May 07, 2014     Points: 20   

I think the DataGridView CheckBox Column will offer some convenience here:

http://www.kettic.com/winforms_ui/csharp_guide/gridview_column_types_checkbox_column.shtml



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend