2010-07-08 5 views
1

DataGridView CalendarColumn이 있습니다. 기본적으로 데이터베이스 테이블에 바인드 된 열이 NULL 인 경우 현재 열이 표시되지만 NULL로 설정해야합니다.DataGridview CalendarColumn에서 NULL 값 선택을 활성화하는 방법

예를 들어 특정 날짜 열에 대한 데이터가 있으면 사용자가 날짜 셀을 비워두기 (NULL) 만 할 수 있기를 원하지만이를 수행 할 속성을 찾을 수 없습니다. 모든 아이디어, DataGridView를의 Calendercolumn

답변

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; 
} 
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; 
     } 
    } 
} 
을에 행동의이 종류를 얻을 수이다