DataGridView CalendarColumn

  • Thread starter Thread starter Chris Gin
  • Start date Start date
C

Chris Gin

I'm using the CalendarColumn from http://msdn2.microsoft.com/en-us/library/7tas5c80.aspx

I've found a problem where the date is not being retained if it's
entered via the keyboard. If you enter a cell, type one number, then
tab out, the cell loses its value. If you type TWO numbers (e.g. "12"
or "04"), then tab out, the cell keeps its value. Also if you type
one number then use the cursor keys to move to a different part of the
date (e.g. from day to month) then it retains the value when you tab
out.

Has anyone come across this problem before, and is there a
workaround?

I found the same problem logged here, but no decent workaround seems
to exist: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1624484&SiteID=1&mode=1

Chris
 
I do not see this sort of problem with my DateTime picker control. Perhaps
it is because I've added code that explicitly detects when the control has
changed value.

My organization varies a bit from the original sample. I created a new User
Control class named DateTImePickerControl into which I inserted a
DateTimePicker. The only two methods in this class are the wizard supplied
constructor and a data accessor that returns the embedded DateTimePicker
control. This User Control approach was done so that VS05 would be happy. I
could have gone straight at a DateTimePicker control but that confuses VS05.
A double click on the code module in the Solution Explorer brings up a gray
error page saying that it can't display the design view and you have to
click on a hyper link to see the module displayed in code view.

Anyway, the Editing class looks something like this:

public partial class DateTimePickerControl : UserControl
{
public DateTImePicker DateTimePicker
{
get { return dateTimePicker; }
}
// Stuff clipped for brevity...
}

public class GridDateEditing Control : DateTimePickerControl,
IDataGridViewEditingControl
{
public GridDateEditingControl()
{
// lots of stuff clipped for brevity...
DateTimePicker.ValueChanged += new
EventHandler(DateTimePicker_ValueChanged);
}

void DateTimePicker_ValueChanged( object sender, EventArgs e )
{
// Code that notifies the DataGridView that the cell has changed...
}
}
 
Back
Top