Beispiel #1
0
        public override void InitializeEditingControl(int rowIndex, object
                                                      initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            // Set the value of the editing control to the current cell value.
            base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
            CalendarEditingControl ctl = DataGridView.EditingControl as CalendarEditingControl;

            // Use the default row value when Value property is null.
            if (this.Value == null)
            {
                ctl.NValue = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); //(DateTime?)this.DefaultNewRowValue;
            }
            else
            {
                try { ctl.NValue = (DateTime)this.Value; } catch (Exception) { ctl.NValue = (DateTime?)this.DefaultNewRowValue; }
            }
        }
        public override void InitializeEditingControl(int rowIndex, object
                                                      initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            // Set the value of the editing control to the current cell value.
            base.InitializeEditingControl(rowIndex, initialFormattedValue,
                                          dataGridViewCellStyle);
            CalendarEditingControl ctl =
                DataGridView.EditingControl as CalendarEditingControl;

            // Use the default row value when Value property is null.
            if (this.Value == null || Common.FixNullstring(this.Value) == "")
            {
                ctl.Value = (DateTime)this.DefaultNewRowValue;
            }
            else
            {
                DateTime dtValue = DateTime.Now;
                DateTime.TryParse(Common.FixNullstring(this.Value), out dtValue);
                //ctl.Value = (DateTime)this.Value;
                ctl.Value = dtValue;
            }
        }