简体   繁体   中英

WPF datagrid custom column

Is there a solution to bind from a dataset a collumn and convert the database DateTime value to Date value and display it? Also i would like a boolean column from the database to be displayed as True/ False and not checkbox...Any ideas?

You can use converters to control the way the bound data is displayed

For instance, to display true/false:

[ValueConversion(typeof(bool), typeof(string))]
public class TrueFalseConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        bool boolean = (bool)boolean;
        return boolean.ToString();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
// Convert the other way around if needed else throw NotImplementedException...
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM