We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Custom DateTimeCell cell type

Thread ID:

Created:

Updated:

Platform:

Replies:

70043 Nov 23,2007 09:22 PM UTC Nov 26,2007 10:14 PM UTC Windows Forms 3
loading
Tags: GridControl
Mark Atkinson
Asked On November 23, 2007 09:22 PM UTC

I'm trying to implement your DateTimeCellModel/Renderer classes (..\Samples\2.0\CustomCellTypes\DateTimePickerCells\CS\) and am mostly having some success except for a couple of issues that I could use some help on.
#1) When I'm focused on one DateTimeCell and move to another, the second cell is rendered with the value of the cell I was just on. Is there a known way to prevent this?
#2) Once I pick a value, I can't seem to lose focus/exit the cell unless I choose a different (non-DateTimeCell) cell in the same grid. That is, I can't click on to a different control on my form to lose focus.
#3) I' had some trouble with setting null values using the 'None' button in the drop down but I think I've resolved them with this code:

In OnInitialize:
if ( !Convert.IsDBNull (style.CellValue))
dateTimePicker.Value = (DateTime)style.CellValue;

In OnSave:
if (dateTimePicker.IsNullDate)
style.CellValue = DBNull.Value;
else
style.CellValue = dateTimePicker.Value;



Administrator [Syncfusion]
Replied On November 25, 2007 09:06 AM UTC

>>In OnInitialize:
if ( !Convert.IsDBNull (style.CellValue))
dateTimePicker.Value = (DateTime)style.CellValue;


What value do you want to see in the dateTimePicker when the cell contains DBNull? If you set no value, then the dateTimePicker will retain the value that it last had. This might explain why you are seeing the last value when you click on an empty cell.

Try this code. In the DateTimeCellRenderer constructor, add:

dateTimePicker.NullString = "";


Then use this OnInitialize:

protected override void OnInitialize(int rowIndex, int colIndex)
{
// Immeditaly switch into editing mode when cell is initialized.
GridStyleInfo style = Grid.Model[rowIndex, colIndex];

if (style.Text.Length > 0 && !Convert.IsDBNull(style.CellValue))
dateTimePicker.Value = (DateTime)style.CellValue;
else
dateTimePicker.IsNullDate = true;

CurrentCell.BeginEdit();
base.OnInitialize(rowIndex, colIndex);
dateTimePicker.ValueChanged += new EventHandler(datePicker_ValueChanged);
dateTimePicker.ShowDropButton = style.ShowButtons != GridShowButtons.Hide;
dateTimePicker.Update();
}





Mark Atkinson
Replied On November 26, 2007 05:02 PM UTC

I was using the NullString and checking for IsDBNull but I wasn't implementing an else condition in my OnInitialize method to set the IsNullDate = true

Thanks for your help, this is working well.
By the way, I think this model/renderer idea for implementing custom cell types is great. It's come in handy for me for a few different cell types I've created.

>>>In OnInitialize:
if ( !Convert.IsDBNull (style.CellValue))
dateTimePicker.Value = (DateTime)style.CellValue;


What value do you want to see in the dateTimePicker when the cell contains DBNull? If you set no value, then the dateTimePicker will retain the value that it last had. This might explain why you are seeing the last value when you click on an empty cell.

Try this code. In the DateTimeCellRenderer constructor, add:

dateTimePicker.NullString = "";


Then use this OnInitialize:

protected override void OnInitialize(int rowIndex, int colIndex)
{
// Immeditaly switch into editing mode when cell is initialized.
GridStyleInfo style = Grid.Model[rowIndex, colIndex];

if (style.Text.Length > 0 && !Convert.IsDBNull(style.CellValue))
dateTimePicker.Value = (DateTime)style.CellValue;
else
dateTimePicker.IsNullDate = true;

CurrentCell.BeginEdit();
base.OnInitialize(rowIndex, colIndex);
dateTimePicker.ValueChanged += new EventHandler(datePicker_ValueChanged);
dateTimePicker.ShowDropButton = style.ShowButtons != GridShowButtons.Hide;
dateTimePicker.Update();
}







Mark Atkinson
Replied On November 26, 2007 10:14 PM UTC

Another small thing I added to the OnInitialize method was this:

if (dateTimePicker.Focused)
CurrentCell.BeginEdit();

...calling BeginEdit without some check seems to force the focus in the cell when you've clicked on another control in the parent form.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;