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

GridViewDateTimeColumn handling null values

1 Answer 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
scottw
Top achievements
Rank 1
scottw asked on 06 Aug 2013, 05:25 PM
I have a GridView with a  GridViewDateTimeColumn, and I have managed to figure out how to display no text in the editor when the cell value is null, however I need to also allow the user the  option of setting the value to null if a value exists.

When the pop up editor appears, i cannot see a way to customize the popup or the text editor to allow this to happen.

        private void gvLibrary_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            GridTimePickerEditor editor = e.ActiveEditor as GridTimePickerEditor;
            if (editor != null)
            {
                RadTimePickerElement editorElement = editor.EditorElement as RadTimePickerElement;
                editorElement.Format = "HH:mm:ss";
                editorElement.NullText = "";
                editorElement.NullValue = 0;
                if (e.Value != null)
                {
                    editorElement.Value = e.Value; 
                }
                else
                {
                    ((TextBox)(editorElement.MaskedEditBox.TextBoxItem.TextBoxControl)).Text = "";
                }
            }
        }

Can you provide me with the necessary elements to allow the user to delete values in the text box or from the pop-up and a way to ensure that the editor's null value is passed to the grid cell?

Thank you,

Vania

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 09 Aug 2013, 03:07 PM
Hi Scott,

Thank you for writing.

We kindly ask you to use just one support channel to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets/forum posts instead of one. Moreover threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread. However I am copying my answer here as someone may find it helpful. 

I am copying my answer here as well, so the community can benefit from it:

You can clear the editor by calling the SetToNullValue method of the RadDateTimeEditorElement. For example it can be done when the user presses the Delete Key. Please take a look at the code below:
void grid_CellEditorInitialized(object sender, GridViewCellEventArgs e)
 
{
     RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
     if (editor != null)
 
    {
         RadDateTimeEditorElement editorElement = editor.EditorElement as RadDateTimeEditorElement;
         editorElement.KeyUp -= editorElement_KeyDown;
         editorElement.KeyUp += editorElement_KeyDown;
         editorElement.NullText = "";
     }
 }
 void editorElement_KeyDown(object sender, KeyEventArgs e)
 
{
     if (e.KeyCode == Keys.Delete)
     {
         (sender as RadDateTimeEditorElement).SetToNullValue();
     }
 }

Thank you for your understanding.
 
Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
scottw
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or