2010-05-03 59 views
0

我的自定義DataGridViewCell有問題,的確我試圖寫入我的datagridviewcell的自定義屬性,但我不能因爲它不可訪問。這是我的代碼:如何更改DataGridViewCellCollection的類型返回以適應自定義DatagridViewCell

namespace MonthCalendarLibrary 
{ 
    public class MonthCalendarCell : DataGridViewImageCell 
    { 

     public DateTime date { get; set; } 

     public MonthCalendarCell() : base() 
     { 
      this.date = new DateTime(); 
      this.date = DateTime.Today; 
     } 


     public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) 
     { 
      base.InitializeEditingControl(rowIndex, initialFormattedValue, 
       dataGridViewCellStyle); 
      this.ReadOnly = false; 

      MonthPanelEvent ctl = DataGridView.EditingControl as MonthPanelEvent; 

     } 

     public override Type EditType 
     { 
      get 
      { 
       // Return the type of the editing contol that CalendarCell uses. 
       return typeof(MonthPanelEvent); 
      } 
     } 

     public override Type ValueType 
     { 
      get 
      { 
       // Return the type of the value that CalendarCell contains. 
       return typeof(Image); 
      } 
     } 


     public override object DefaultNewRowValue 
     { 
      get 
      { 
       // Use the current date and time as the default value. 
       return Image.FromFile("C:\\blank.jpg"); 
      } 
     } 

     protected override void OnMouseClick(DataGridViewCellMouseEventArgs e) 
     { 
      if (base.DataGridView != null) 
      { 
       Point point1 = base.DataGridView.CurrentCellAddress; 
       if (((point1.X == e.ColumnIndex) && (point1.Y == e.RowIndex)) && (e.Button == MouseButtons.Left)) 
       { 
        if (base.DataGridView.EditMode != DataGridViewEditMode.EditProgrammatically) 
        { 
         base.DataGridView.BeginEdit(true); 
        } 
       } 
      } 
     } 

     public override object Clone() 
     { 
      MonthCalendarCell dataGridViewCell = base.Clone() as MonthCalendarCell; 

      if (dataGridViewCell != null) 
      { 
       dataGridViewCell.date = this.date; 
      } 

      return dataGridViewCell; 
     } 

    } 
} 

這是我的代碼,當我試圖查看在此屬性:

this.Rows[i].Cells[j].date = this.jourDuMois.ElementAt(i * 7 + j); 

我的問題是樣品(我認爲),我怎麼能存取權限這個屬性?

難道,我不得不改變datagridviewcellcell的返回類型嗎?或者有另一種解決方案。

預先感謝您。

此致敬禮

P.S. :對不起我的英文,我是法國人。

回答

1
MonthCalendarCell cell = this.Rows[i].Cells[j] as MonthCalendarCell; 
if(cell != null) 
{ 
    cell.date = this.jourDuMois.ElementAt(i * 7 + j); 
} 
+0

謝謝你的幫助,正是我的預期^^ – Kovscer 2010-05-04 11:21:49

相關問題