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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Datagrid checkbox check uncheck in single click

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :WPF
Hi, I have a datagrid colums of checkbox type. Users have to click twice on the checkbox to check or uncheck. Is there a way to do this in one click. Thanks Vijay

View Complete Post

More Related Resource Links

Getting a Checkbox in a datagrid to check before RowDetails expand the row.



I am having trouble getting a checkbox in my datagrid to check in certain situations. The row details in my grid cause the row to expand when the row is selected. When no row is selected, or a row below the row just clicked was the selected row prior to the click, things work fine (the checkbox I clicked on gets toggled and the row expands to show its rowdetails). If a row above the row I am clicking was selected (and therefore expanded, showing its rowdetails) when that row collapses, my current row moves up (because the row above collapsed) and the current row expands. However, the checkbox in that row (in the column that I clicked on) does not get checked in this case. I suspect it's because it is no longer in the space where the click occurred (because it works if clicking this checkbox/row doesn't cause it to move up before expanding). Is there a way to get the checkbox click to happen before the row selection? I seem to recall properties on controls in the past that indicated whether they answered before or after their child controls (maybe that was forms) but I cannot find any such property to set on the WPF DataGrid. Any suggestions? Thanks.


check or uncheck boxes in datagrid using Javascript


Here is the situation: I have a checkbox in the header of the datagrid and I want to use Javascipt so when I check the box, all of the checkboxes in the datagrid are checked (or unchecked if the one on top is unchecked).  How do I reference the asp:checkboxes in the datagrid?

<script type="text/javascript" language="javascript" id="clientEventHandlersJS">
    function SelectAll(isChecked) {
        var chkb = document.getElementsByTagName('asp:checkbox')
        for (var i = 1; i < chkb.length; i++) {
            chkb[i].checked = isChecked;

<asp:DataGrid id="DataGrid2" runat="server">
        <asp:TemplateColumn SortExpression="InMailing" HeaderText="In Mailing">
            <HeaderTemplate >

uncheck single checkbox in gridview template



i have two checkboxes  in two templete fileds in a gridview .

but i want to  uncheck only single checkbox when i click on button which is ouside of the grid,


How to check if at least one checkbox is checked in a DataGrid



I was trying to find out if there are any check boxes checked in the datagrid, if non of them is checked it should show me an alert to select atleast one.

My problem starts when there is paging in datagrid...

not able to check the entire datagrid at a time in itemDataBound event for the checked check boxes !!!!!


How to get Click event to work with checkbox


I am new to ASP.Net and I'm having trouble figuring out what needs to be where in my code.  I have a webform with 2 listboxes and 2 checkboxes... When I check checkbox1 I want listbox1 to be disabled and checkbox2 to be disabled.  Similarly, when I check checkbox2 I want listbox2 to be disabled and checkbox1 to be disabled.  The code does not show any errors; however, when I run the Page everything appears as it is supposed to but when I check the boxes, nothing happens.  What am I missing that will link the code on the .aspx.vb page to the objects on the .aspx page and make them work together?

Here is my code for Page1.aspx.vb:

Public Class LCPage1
    Inherits System.Web.UI.Page

    Protected Sub AllClients_Click(ByVal sender As ObjectByVal e 

Styling a checkbox so the check goes outside the box

Hi all.  I'm trying to style a checkbox so that the custom check mark goes outside the border.  I normally would make this work by setting a negative margin, but the border of the checkbox constrains the contents, so that only the bit drawn inside is visible ?  This is what I have:       <Style x:Key="{x:Type CheckBox}" TargetType="CheckBox">     <Setter Property="SnapsToDevicePixels" Value="true"/>     <Setter Property="OverridesDefaultStyle" Value="true"/>     <Setter Property="Template">     <Setter.Value>     <ControlTemplate TargetType="CheckBox">     <BulletDecorator Background="Transparent">     <BulletDecorator.Bullet>     <Border x:Name="Border"   Width="13"   Height="13"   Margin="-3,-3,3,3"   CornerRadius="0"   Background="Transparent"   BorderThickness="1"   BorderBrush="Black">     <Path   Width="16" Height="16"   Margin="3,-3,0,0"   x:Name="CheckMark"   SnapsToDev

How to get the combobox value inside Datagrid on Edit button click event

Hi     I have Datagrid template column like<DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>DataGridTemplateColumn Header="Edit" x:Name="Edit" ><DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>SelectionChanged="cmbDGTeam_SelectionChanged" IsTabStop="True" /></DataTemplate><ComboBox Height="22" IsEditable="True" IsReadOnly="True" ItemsSource="{Binding}" DisplayMemberPath="Title" SelectedValuePath="TeamID" x:Name="cmbDGTeam"  SelectedValue="{Binding Path=TeamID,Mode=TwoWay}"<DataGridTemplateColumn.CellEditingTemplate><DataTemplate><DataTemplate><TextBlock Text="{Binding Title}"/></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn Header="Team" Width="75"><DataGridTemplateColumn.CellTemplate> and Edit button Template column <DataGridTemplateColumn Header="Edit" x:Name="Edit" > </DataGridTemplateColumn.CellTemplate></DataTemplate><Button Content="Edit" IsEnabled="False" x:Name="btnEdit" Click="btnEdit_Click" ></Button>&l

WPF Datagrid with multiple row selection/checkbox column template

Hello, I am using the WPF Toolkit Datagrid with a checkbox defined in a template column/template cell. We are using the checkbox template so that selecting the checkbox will also highlight the row in the datagrid. Here is the template definition: <dg:DataGridTemplateColumn MinWidth="50" Width="Auto" Header="" CanUserReorder="False"> <dg:DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox IsChecked="{Binding Path=IsCheckedm, Mode=TwoWay}" /> </DataTemplate> </dg:DataGridTemplateColumn.CellTemplate> </dg:DataGridTemplateColumn> We are allowing multiple row selection in the datagrid and using MVVM (using MVVM Light). We would like to keep a list in the View Model of selected rows as they are selected/unselected. Any suggestions on how we can leverage MVVM to keep the list of selected/unselected elements current. Many Thanks --Sam

Populate Grid/Listbox depending on the click of checkbox of treeviewitem of treeview in wpf

Hi, I am using your TreeViewWithCheckBoxes example (http://www.codeproject.com/KB/WPF/TreeViewWithCheckBoxes.aspx) in my code. on the basis of checked state in treeview I have to populate a grid. How to go about that. Ex: If Suppose Root Child1 Child1.1 Child1.2 Child2 Child2.1 Child3 Child3.1 Child3.2 is the treeview with checkboxes, and I check, Child1.1 or Root(all treeviewitems selected) node then I have to populate a grid/listbox on the selection basis. Thanks, Manu G

checkbox in listview layout template check select all checkboxes in listview itemtemplate

hi,how to do this when the checkbox in listview layout template check select all checkboxes in  listview itemtemplate.I dont give 'Eval 'field to checkbox present in itemtemplate.pls reply me.Many thanks in advance.

Click.CommandParameter null when binding on Button inside DataGrid DataGridTemplateColumn

I am having trouble getting a Click.CommandParameter to pass through with a bound Click.Command. I have a DataGrid with a DataGridTemplateColumn that contains a couple of Buttons. Using a suggestion found on the forum (http://social.msdn.microsoft.com/Forums/en/wpf/thread/541024a9-3d7e-4c6a-b88e-9a7eb7ee83a9), I was able to get the Click.Command to bind to the right command, but when arriving in the corresponding method in my ViewModel, the parameter is null.  Here is my xaml for my DataGridTemplateColumn <data:DataGridTemplateColumn Header="Case">  <data:DataGridTemplateColumn.CellTemplate>   <DataTemplate >    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">     <Button Content="Open" Margin="6,0" command:Click.Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type data:DataGrid}}, Path=DataContext.OpenCaseCommand}" CommandParameter="{Binding}"  />     <Path Data="M1,1 L1,2" Stroke="#FFCCCCCC"/>     <Button Content="Rename" />    </StackPanel>   </DataTemplate>  </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> I used Snoop to see what was going on. Everything

Which Row from DataGrid CheckBox

I have got as far as creating an Event handler from a DatGrid CheckBox click event and can have a MessageBox pop up to confirm this is working. I am trying to unravel how to identify which row of my Bound ObservableCollection has been selected. can anyone help please? <DataGridCheckBoxColumn Width="50" Header="Select" x:Name="chkSelection"> <DataGridCheckBoxColumn.ElementStyle> <Style TargetType="CheckBox"> <EventSetter Event="CheckBox.Click" Handler="OnCheckBoxClick" /> </Style> </DataGridCheckBoxColumn.ElementStyle> </DataGridCheckBoxColumn> Private Sub OnCheckBoxClick(ByVal sender As Object, ByVal e As RoutedEventArgs) Dim test As String test = e.Source.ToString() MsgBox("CheckBox " & test) End Sub   Miswod?  

Uncheck one checkbox when another checkbox unchecks ?

For a lack of a checkboxlist in WPF I'm using 11 single checkboxes.  I have a "selectall" checkbox.  I have it set so when I check selectall, all checkboxes get checked and when I uncheck selectall, all checkboxes get unchecked (so far so good). My problem is that I want to deselect selectall when any of the other checkboxes get unchecked.  With the checkboxlist in forms it was easy with some logic, but I'm lost in wpf.  I don't want to code the uncheck event for every checkbox on the app.  IS there a way to do it via the XAML code? even if I have to do it on all checkboxes.NR

Highlight a treeviewitem Text on click of Checkbox in WPF



 I want to highlight the text of checked treeviewitem of a treeview in wpf.

Treeview contains check boxes for all the items. So when a user checks a treeviewitem. the text associated with it should be highlighted. Right now I am doing this on treeview checked method. Is there any other way. Like doing it by triggers.

Insert/Update data to multiple tables on a single button click


Hi experts,

I need to insert/update data to 3 or more tables on a single button click.What is best method for achieving this?I am using mysql as my DB.

Thanks for your valuable reply in advance.

How can i check if button clicked inside a button click event?


private void View_Log_File_Click(object sender, EventArgs e)
                processNotePad = System.Diagnostics.Process.Start("notepad.exe", path_exe + @"\log\logger.txt");


It was easy to check it inside a checkbox event for example:


private void Show_satistics_CheckedChanged(object sender, EventArgs e)


             if (Show_satistics.Checked)
                     statform = new StatisticForm();

Single Click File Upload with Preview and no heartache


Combing the web for a simple file uploader for ASP.NET with a server side save and preview capability didn't reveal anything simple, and I noticed a lot of people were struggling to get something too.

I figured this example out today. It uses existing techniques and is simple. Downside is that you have to use session for the temporary store, and the Ajax AsyncFileUpload usess session too.

Written in VS 2010 - I hope you find it useful. This is the basic working code - that should easily be exandable even for more demanding requirements such as  Repeater controls etc.


<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="FileUploader._Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/javascript">
        function uploadComplete() {
            requestImgUrl("", "");

        function dataFromServer(imgUrl) {
            document.getElementById("Image1").src = imgUrl;
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

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