1

DataGridView CalendarColumn があります。デフォルトでは、データベース テーブルにバインドされている列が NULL の場合、現在の値が表示されますが、それも NULL にする必要があります。

たとえば、その特定の日付列のデータの場合、ユーザーが日付セルを空(NULL)にできるようにしたいのですが、これを実現するために設定するプロパティが見つかりません。DatagridviewのCalendercolumnでこの種の動作を実現することは、どんなアイデアでも可能です

4

2 に答える 2

1
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;
        }
    }
}
于 2010-12-09T09:17:46.920 に答える
0
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;
}
于 2010-12-09T09:05:17.527 に答える