I want a button to be disabled or enabled based on whether or not a user checks a checkbox on a row in my grid. I can caption the datarecord -- but how do I actually get the button out of the datarecord so that I can disable the button?
Also, both checkbox and button are in CellValuePresenter.
That is to say they are each in their OWN unbound column, but in their own CellValuePresenter.
Bump
Hello,
You can use our helper methods to search up/down in the element tree of you application.
Infragistics.Windows.Utilities.GetAncestorFromType(...);
Infragistics.Windows.Utilities.GetAncestorFromName(...);
Infragistics.Windows.Utilities.GetDescendantFromType(...);
Infragistics.Windows.Utilities.GetDescendantFromName(...);
Hope this helps.
Thanks -- I would have never figured this out. I don't suppose you ahve any exampels of how to call this...
Well,
I read again the initial post, and I see that you want to change the IsEnabled property of the Button according to a checkbox from another field. This can be done in the xaml, without any procedural code. You can try this:
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="b">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Button Name="cmdEditBuyout"
Background="{TemplateBinding Background}"
MaxWidth="20" Content="ED"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Cells[0].Value}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
I am also attaching the sample project for this.
The procedural code for this should look something like:
On Cell Updated Event
check if the cell is the the one with the checkbox,
then:
DataRecordPresenter drp = DataRecordPresenter.FromRecord(e.Cell.Record) as DataRecordPresenter;
if ((bool)e.Cell.Value == false)
{
Button b = Utilities.GetDescendantFromName(drp, "cmdEditBuyout") as Button;
b.IsEnabled = false;
}
This also works for me -- I actually capture the button event -- I did not tell you but I have a xamchk button in the grid so here's how I ended up doing it.
DataRecord dr = ((XamCheckEditor)sender).DataContext as DataRecord; DataRecordPresenter drp = DataRecordPresenter.FromRecord(dr.Cells["BuyOutEditButton"].Record) as DataRecordPresenter; Button b = Infragistics.Windows.Utilities.GetDescendantFromName(drp, "cmdEditBuyout") as Button; b.IsEnabled = (bool)((XamCheckEditor)sender).Value;
THANK YOU!!!!