GridViewMaskBox for time showing date too

3 posts, 0 answers
  1. Brandon
    Brandon avatar
    2 posts
    Member since:
    Nov 2014

    Posted 26 Dec 2014 Link to this post

    I'm attempting to setup a gridview in which one of the columns is a date-only field.  In order to achieve this, I'm using a gridViewMaskBox.  The below code shows a correct 00:00 AM on edit, but after the cell is no longer being edited, the field shows date and time.  Setting a FormatString for the column does not change this behavior.  Any help or suggestions?

                gridViewMaskBoxColumn1.EnableExpressionEditor = false;
                gridViewMaskBoxColumn1.FieldName = "From";
                //gridViewMaskBoxColumn1.FormatString = "{0:hh:mm tt}";
                gridViewMaskBoxColumn1.HeaderText = "From";
                gridViewMaskBoxColumn1.Mask = "t";
                gridViewMaskBoxColumn1.MaskType = Telerik.WinControls.UI.MaskType.DateTime;
                gridViewMaskBoxColumn1.Name = "From";
                gridViewMaskBoxColumn1.Width = 94;
  2. Brandon
    Brandon avatar
    2 posts
    Member since:
    Nov 2014

    Posted 26 Dec 2014 in reply to Brandon Link to this post

    The original post stated that I'm attempting to create a date-only field.  That is incorrect, I'm attempting to create a time-only field.  Sorry for the confusion!
  3. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3204 posts

    Posted 30 Dec 2014 Link to this post

    Hello Brandon,

    Thank you for writing.

    In order to achieve your goal, it is suitable to use a GridViewDateTimeColumn. Thus, you can specify the format of the text part by setting the FormatString property. Additionally, you can use the Format property to specify the desired format for the editor. Note that you can hide the arrow button appearing for the date time picker by using the CellEditorInitialized event. Here is a sample code snippet:
    GridViewDateTimeColumn dateTimeColumn = new GridViewDateTimeColumn("DateTimeColumn");
    dateTimeColumn.FormatString = "{0:hh:mm tt}";
    dateTimeColumn.Format = DateTimePickerFormat.Custom;
    dateTimeColumn.CustomFormat = "t";
    dateTimeColumn.Width = 100;
    radGridView1.MasterTemplate.Columns.Add(dateTimeColumn);
     
    this.radGridView1.CellEditorInitialized+=radGridView1_CellEditorInitialized;
    private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDateTimeEditor timeEditor = e.ActiveEditor as RadDateTimeEditor;
        if (timeEditor!=null)
        {
            RadDateTimeEditorElement el = timeEditor.EditorElement as RadDateTimeEditorElement;
            el.ArrowButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.
     
    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top