开发者

How to enable NULL value selection in DataGridview CalendarColumn

I have a DataGridView CalendarColumn. By default, if the column its bound to in the database table is NULL, its shows the current, but i have a requirements to make it just NULL as well.

For example if the data for that particular date column, i want a user to be able to just make the Date Cell empty(NULL) but i cant find a property to set to achieve this. Any ideas, is to poss开发者_运维技巧ible to achieve this kind of behaviour in a Datagridview's Calendercolumn


public object EditingControlFormattedValue {
    get {
        if (this.ShowCheckBox && !this.Checked) {
            return String.Empty;
        } else {
            if (this.Format == DateTimePickerFormat.Custom) {
                return this.Value.ToString();
            } else {
                return this.Value.ToShortDateString();
            }
        }
    }
    set {
        string newValue = value as string;
        if (!String.IsNullOrEmpty(newValue)) {
            this.Value = DateTime.Parse(newValue);
        } else if (this.ShowCheckBox) {
            this.Checked = false;
        }
    }
}


ctl.ShowCheckBox = this.isNullable;
if (this.Value != null && this.Value != DBNull.Value) {
    if (this.Value is DateTime) {
        ctl.Value = (DateTime)this.Value;
    } else {
        DateTime dtVal;
        if (DateTime.TryParse(Convert.ToString(this.Value), out dtVal)) ctl.Value = dtVal;
    }
    if (this.isNullable) ctl.Checked = true;
} else if (this.isNullable) {
    ctl.Checked = false;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜