protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
        {
            if (value == null)
            {
                value = String.Empty;
                return(base.GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context));
            }
            DataGridViewDateTimeColumn col = (DataGridViewDateTimeColumn)OwningColumn;

            if (col.Format == DateTimePickerFormat.Custom)
            {
                value = ((DateTime)value).ToString(col.CustomFormat);
            }
            else if (col.Format == DateTimePickerFormat.Long)
            {
                value = ((DateTime)value).ToLongDateString();
            }
            else if (col.Format == DateTimePickerFormat.Short)
            {
                value = ((DateTime)value).ToShortDateString();
            }
            else
            {
                value = ((DateTime)value).ToLongTimeString();
            }
            return(base.GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context));
        }
Esempio n. 2
0
 /// <summary>
 /// Implements the auto complete mode
 /// </summary>
 /// <param name="e"></param>
 private void DataGridViewExtension_EditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
 {
     if (Columns[CurrentCell.ColumnIndex].GetType() == typeof(DataGridViewAutoCompleteTextboxColumn))
     {
         DataGridViewAutoCompleteTextboxColumn col = (DataGridViewAutoCompleteTextboxColumn)Columns[CurrentCell.ColumnIndex];
         TextBox t = e.Control as TextBox;
         t.AutoCompleteCustomSource = col.AutoCompleteCollection;
         t.AutoCompleteMode         = col.AutoCompleteMode;
         t.AutoCompleteSource       = col.AutoCompleteSource;
     }
     else if (Columns[CurrentCell.ColumnIndex].GetType() == typeof(DataGridViewDateTimeColumn))
     {
         DataGridViewDateTimeColumn col = (DataGridViewDateTimeColumn)Columns[CurrentCell.ColumnIndex];
         DateTimePicker             t   = e.Control as DateTimePicker;
         t.Format = col.Format;
         if (col.Format == DateTimePickerFormat.Custom)
         {
             t.CustomFormat = col.CustomFormat;
         }
         t.ShowUpDown = col.ShowUpDown;
     }
 }