开发者

How to change the type return by DataGridViewCellCollection to fit Custom DatagridViewCell

I have a problem with my custom DataGridViewCell, indeed i tried to write to a custom property of my datagridviewcell but i cannot because it's not accesible. This is my code:

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.Editi开发者_StackOverflow社区ngControl 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;
        }

    }
}

And this is my code when i tried to acces to this property :

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

My question is sample ( I think ), how can i acces this property ?

Do, i have to change the type return by the datagridviewcellcollection ? or there is another solution.

Thank you in advance.

Best regards,

P.S. : Sorry for my english, i'm french.


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜