Hi,
I am using dependency property to update checkbox values in tree list.
My code is as below:
C#public static readonly DependencyProperty Val1Property =
DependencyProperty.RegisterAttached("Val1", typeof(bool), typeof(frmECISOCode), new PropertyMetadata(false));
public static bool GetVal1(DependencyObject obj)
{
return (bool)obj.GetValue(Val1Property);
}
public static void SetVal1(DependencyObject obj, bool value)
{
obj.SetValue(Val1Property, value);
}
// Using a DependencyProperty as the backing store for Val2. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Val2Property =
DependencyProperty.RegisterAttached("Val2", typeof(bool), typeof(frmECISOCode), new PropertyMetadata(false));
public static bool GetVal2(DependencyObject obj)
{
return (bool)obj.GetValue(Val2Property);
}
public static void SetVal2(DependencyObject obj, bool value)
{
obj.SetValue(Val2Property, value);
}
My code in xaml file:
C#<dxg:TreeListColumn Header="Is Redundant" FieldName="ColIsRedundantCode" UnboundType="Boolean" Binding="{Binding ColIsRedundantCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
<dxg:TreeListColumn.CellTemplate>
<DataTemplate >
<dxe:CheckEdit x:Name="PART_Editor"
Visibility="{Binding RowData.Row ,Converter={StaticResource ChildNodeVisibilityConverter}}"
IsChecked="{Binding Path=RowData.RowState.(local:frmECISOCode.Val1), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="{Binding Path=RowData.RowState.(local:frmECISOCode.Val2), Converter={dxmvvm:BooleanNegationConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</dxg:TreeListColumn.CellTemplate>
</dxg:TreeListColumn>
<dxg:TreeListColumn Header="Is Secondary" FieldName="ColIsSecondaryId" UnboundType="Boolean" Binding="{Binding ColIsSecondaryId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<dxg:TreeListColumn.CellTemplate >
<DataTemplate>
<dxe:CheckEdit x:Name="PART_Editor"
Visibility="{Binding RowData.Row ,Converter={StaticResource ChildNodeVisibilityConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsChecked="{Binding Path=RowData.RowState.(local:frmECISOCode.Val2), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEnabled="{Binding Path=RowData.RowState.(local:frmECISOCode.Val1), Converter={dxmvvm:BooleanNegationConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</dxg:TreeListColumn.CellTemplate>
</dxg:TreeListColumn>
These code works fine at the time of loading.
But when I re-assign the list to treelist itemsource then check boxes are not getting binded. It looks like on rebinng the grid does not call these dependency properties.
Can you please let me know the actual cause?
Thanks,
Ripal
Hi,
I also face this issue when I try to add or remove child node. When I try to do that then checkbox gets unchecked.
On scrolling heck boxes get checked again.
Hello,
I've reviewed your code snippet and see that you bind your columns to one data item field using the FieldName/Binding property, but bind CheckEdit to another custom attached property.
For example, your first TreeListColumn is bound to the ColIsRedundantCode field, but CheckBox is bound to the frmECISOCode.Val1 property:
<dxg:TreeListColumn FieldName="ColIsRedundantCode" ... />
<dxe:CheckEdit x:Name="PART_Editor" IsChecked="{Binding Path=RowData.RowState.(local:frmECISOCode.Val1), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
In this case, your column contains data from a real item property but doesn't edit it and it's not fully clear why it's necessary to configure your columns in this way. Would you please clarify why you need to configure TreeListColumns in this way?
Moreover, you set both the FieldName and Binding properties to the same field of your data item:
<dxg:TreeListColumn FieldName="ColIsRedundantCode" Binding="{Binding ColIsRedundantCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
So, TreeListColumn uses two data obtaining mechanisms at once and this may cause data editing and synchronization issues. If you bind TreeListColumn using the Binding property, the FieldName property shouldn't refer to real data fields at your data item level. For example:
<dxg:TreeListColumn FieldName="CustomColIsRedundantCode" Binding="{Binding ColIsRedundantCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
Otherwise, remove the Binding property declaration and keep the FieldName property value only.
According to these points, your overall scenario isn't clear to us, so please describe it in greater detail: why you're using attached properties Val1 and Val2, where their values are stored, how they affect data items. At first glance, you need a column with CheckEdits with states that aren't bound to real data. In this case, I suggest that you take a look at our Unbound Columns feature.
Thanks,
Kirill
Hi,
I have written binding code, so that values can get binded from from database. If I do not write this code then values from DB do not get binnded.
Binding="{Binding ColIsRedundantCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
These two lines are being used to get enable/disable check boxes.
<dxe:CheckEdit x:Name="PART_Editor" IsChecked="{Binding Path=RowData.RowState.(local:frmECISOCode.Val1), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding Path=RowData.RowState.(local:frmECISOCode.Val2), Converter={dxmvvm:BooleanNegationConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
I have also attached snapshot of UI.