Is it possible to bind a DataGridCheckBoxColumn to Nullable<DateTime>.HasValue?

946 views Asked by At

I have this column in the database

enddate DATETIME NULL

Entity Framework translated it to

DateTime? ENDDATE

I have a column in my DataGrid

<DataGridCheckBoxColumn
      Binding="{Binding Path=ENDDATE.HasValue}"
      Header="Concluded?" />

But it doesn't work. How to do it?

1

There are 1 answers

0
Phil On BEST ANSWER

This works for me using Mvvm Light:

public class DataItem : ViewModelBase
{
    private double? _number;
    public double? Number
    {
        get { return _number; }
        set
        {
            Set(()=>Number, ref _number, value);
            RaisePropertyChanged(()=>NumberHasValue);
        }
    }

    public bool NumberHasValue
    {
        get { return Number.HasValue; }
    }
}

<Grid>
    <DataGrid x:Name="grid" AutoGenerateColumns="false">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Number}"/>
            <DataGridCheckBoxColumn Binding="{Binding NumberHasValue, Mode=OneWay}"/>
        </DataGrid.Columns>
    </DataGrid>
</Grid>