0

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!

DHN
  • 4,807
  • 3
  • 31
  • 45
SHEKHAR SHETE
  • 5,964
  • 15
  • 85
  • 143
  • 1
    Use Data Binding. Bind checkbox with bool and on button click change the bool value that will automatically update the checkbox. Take a look at Data Bindings and INotifyPropertyChanged – Haris Hasan May 28 '13 at 05:12
  • will you please provide sample code for above? – SHEKHAR SHETE May 28 '13 at 05:14
  • I don't understand the following: *`IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=GlassType}"`*. Can you please show us the VM or underlying structure? – DHN May 28 '13 at 07:04
  • i have changed it to: Sorry to say but i have copied it from else where to demonstrate checkbox in Grid. i am new to WPF. will you please help me to clear all checkbox value on button click? – SHEKHAR SHETE May 28 '13 at 07:10
  • @SHEKHARSHETE: I'll try. Last question, do you want to solve it by using [MVVM](http://msdn.microsoft.com/en-us/magazine/dd419663.aspx) or in code behind? – DHN May 28 '13 at 08:20
  • code behind please..! IsSelected is boolean field. public bool IsSelected {get;set;} – SHEKHAR SHETE May 28 '13 at 08:26

2 Answers2

1

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....

Kushal Patil
  • 205
  • 1
  • 2
  • 14
0

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;
Ashok Damani
  • 3,896
  • 4
  • 30
  • 48