SHEKHAR SHETE
SHEKHAR SHETE

Reputation: 6056

How to uncheck CheckBox on button click in WPF using C#?

I have a CheckBox in GridControl Column. After performing some operation the selected checkboxes inside GridControl must be UNCHECKED on button click in WPF. Any idea?

<dxg:GridControl Name="grdInfill"  Height="700" VerticalAlignment="Center">
    <dxg:GridControl.Columns>
        <dxg:GridColumn  AllowEditing="True">
            <dxg:GridColumn.CellTemplate>
                <DataTemplate>
                    <CheckBox Name="chkSelect"  HorizontalAlignment="Center" 
                        IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=GlassType}"  
                        Checked="CheckEdit_Checked" 
                        Unchecked="CheckEdit_Unchecked" />
                 </DataTemplate>
             </dxg:GridColumn.CellTemplate>
         </dxg:GridColumn>
     </dxg:GridControl.Columns>
     <dxg:GridControl.View>
         <dxg:TableView Name="grdInfillInner"  ShowTotalSummary="True" AutoWidth="True" 
             DetailHeaderContent="True"  ShowIndicator="False" ShowGroupPanel="False" 
             CellValueChanging="grdInfillInner_CellValueChanging">
             <!--GroupRowTemplate="{StaticResource descriptionHeader}"-->
         </dxg:TableView>
     </dxg:GridControl.View>
</dxg:GridControl>
<Button Name="BtnClearAllCheckbox" Content="Clear All Checkbox" Height="20" Width="80" />

Help Appreciated!

Upvotes: 0

Views: 3597

Answers (2)

AKD
AKD

Reputation: 3966

give an Uid to ur checkbox

<CheckBox Uid="CheckAll" />

than use this extension method to find the element inside the dataTemplate--->

public static UIElement FindUid(this DependencyObject parent, string uid)
{
    var count = VisualTreeHelper.GetChildrenCount(parent);
    if (count == 0) return null;

    for (int i = 0; i < count; i++)
    {
        var el = VisualTreeHelper.GetChild(parent, i) as UIElement;
        if (el == null) continue;

        if (el.Uid == uid) return el;

        el = el.FindUid(uid);
        if (el != null) return el;
    }
    return null;
}

Access the CheckBox in code behind like this

CheckBox checkBox = myDataGrid.FindUid("chkSelect") as CheckBox;

Upvotes: 0

Kushal Patil
Kushal Patil

Reputation: 205

Try below.......

 <CheckBox Name="chkSelect"  HorizontalAlignment="Center" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=GlassType,Mode=TwoWay}"

Im guessing there should be property "GlassType"

Public Bool GlassType {get;set;}

use TwoWay mode while binding and set property value GlassType as True false....

Upvotes: 1

Related Questions