This is a migrated thread and some comments may be shown as answers.

ShowUpDown on an GridViewDateTimeColumn

1 Answer 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Svein Thomas
Top achievements
Rank 1
Svein Thomas asked on 01 Nov 2010, 10:38 AM
Hi,

I followed an example i found on this forum with this code:
RadDateTimeEditor editor = this.radGridView1.ActiveEditor as RadDateTimeEditor;
 if (editor != null)
 {
     RadDateTimeEditorElement editorElement = (RadDateTimeEditorElement)editor.EditorElement;
     editorElement.ShowUpDown = true;
 }

This code are inserted into the event CellBeginEdit. 
The problem is when i'm editing the cell. Since i have bounded this grid to a datasource i expect the value (Time) from the datasource to show up in this cell when i'm editing as well as when i'm not editing it.
But instead of showing the value, the value presented is 00:00:00.

The second question is, how can i modify this editorElement to only show hh:mm (ex. 11:30) when editing? 

Regards
Svein Thomas
 RadDateTimeEditor editor = this.radGridView1.ActiveEditor as RadDateTimeEditor;
            if (editor != null)
            {
                RadDateTimeEditorElement editorElement = (RadDateTimeEditorElement)editor.EditorElement;
                editorElement.ShowUpDown = true;
            }I


I

1 Answer, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 01 Nov 2010, 09:53 PM
Hello,

You can do this by handling the CellEditorInitialized event and doing something like this:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadDateTimeEditor editor = this.radGridView1.ActiveEditor as RadDateTimeEditor;
    if (editor != null)
    {
        RadDateTimeEditorElement editorElement = (RadDateTimeEditorElement)editor.EditorElement;
        editorElement.Format = DateTimePickerFormat.Custom;
        editorElement.CustomFormat = "hh:mm";
        editorElement.ShowUpDown = true;
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Tags
GridView
Asked by
Svein Thomas
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or