Home Forums WPF controls Xceed DataGrid for WPF Two more Q about CheckBox columns

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26529 |

    I have got a checkbox column bound to bool property. I want to align checkboxes to center of their cells.
    1) Straightforward approach for the CellContentTemplate
    <DataTemplate x:Key=”m_CheckBoxCellStyle”>
    <StackPanel>
    <CheckBox HorizontalAlignment=”Center” IsChecked=”{Binding Path=.}”/>
    </StackPanel>
    </DataTemplate>
    throws uncatched exception for every checkbox:
    <hr>
    A first chance exception of type ‘System.FormatException’ occurred in mscorlib.dll
    System.Windows.Data Error: 6 : ‘SystemConvertConverter’ converter failed to convert value ” (type ‘String’); fallback value will be used, if available. BindingExpression:Path=.; DataItem=’String’ (HashCode=371857150); target element is ‘CheckBox’ (Name=’cb’); target property is ‘IsChecked’ (type ‘Nullable`1’) FormatException:’System.FormatException: String was not recognized as a valid Boolean.
    at System.Boolean.Parse(String value)
    at System.String.System.IConvertible.ToBoolean(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at MS.Internal.Data.SystemConvertConverter.Convert(Object o, Type type, Object parameter, CultureInfo culture)
    at System.Windows.Data.BindingExpression.ConvertHelper(IValueConverter converter, Object value, Type targetType, Object parameter, CultureInfo culture)’
    <hr>
    When I add custom converter to the binding I discover that before binding to the correct bool value checkbox receives empty string value.
    So the question is what I have to do to avoid this exception.

    2) My checkbox column have to be read-only. But the template above allows to change checkbox state when user clicks on it. How can I achive the same behaviour as default read-only checkbox column?

    Imported from legacy forums. Posted by Nick (had 2573 views)

    Xceed Support
    Member
    Post count: 5658

    1) What I suggest is to created a custom IValueConverter and apply it to the Binding to the checkbox. In the ConvertFrom, make sure that the “” value is handled and that a boolean value is returned for it. The converter will be called a second time with the actual value.

    2) CheckBox.IsEnabled = false;

    Imported from legacy forums. Posted by Marcus [Xceed] (had 324 views)

    User (Old forums)
    Member
    Post count: 23064

    1) As I mentioned above I have disigned one already. I think this is wrong way. But if this binding behaviour is a bag I can treat this solution as a workaround.
    2) Disabled CheckBox look very different from enabled. Default read-only checkbox column looks like enabled.

    Imported from legacy forums. Posted by Nick (had 3564 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.