Issues with RadGridView column data types

4 posts, 1 answers
  1. MO
    MO avatar
    23 posts
    Member since:
    Jul 2012

    Posted 23 Sep 2013 Link to this post

    I have been using the wizard to create a RadGridView on a VB .NET 4.5 WinForms application. Going into the "open Property Builder" aspect of the wizard. I need to create a column of "dates" and I've tried several ways to do it.

    I tried using the GridViewDateTimeColumn, figuring there was a way to turn off the "time" portion of it. I cannot find it. I feed the date from the database as a "Date" format, so the cell displays "9/25/2013 12:00:00 AM" instead. There were additional problems with the mask, but I can't remember what they were off-hand.

    So I tried using the GridViewTextBoxColumn and discovered that it will insert the date, but that it does comparisons as strings. And in one of my gridviews, it still has the time portion even though I even parse the data using the .NET parsing for date only!

    The data coming from the database is "CONVERT(DATE, DtField)" so I know it should be coming back as a date only.

    I even looked into building the gridview programmatically, but I can't find any entry for a GridViewDateColumn (or something like it) anywhere.

    What am I missing? Is there no strict "date" only column or ability to adjust the date/time column to date-only?

    Oh and one more thing: it appears that even if I handle the cell_doubleclick event of the gridview (the intent is to insert the current date on doubleclick of the cell), the gridviewtextboxcolumn cell on the inside does not allow you to double-click it -- is it treated separately? I haven't tried to fix this yet, as I'm fixing other bigger issues, but I'm wondering if there is a way to let the event bubble down or to grab it bubbling up? (for that matter, I haven't seen any way to grab events bubbling up... do they even bubble events up out of the RadGridView?)



  2. Answer
    George
    Admin
    George avatar
    500 posts

    Posted 26 Sep 2013 Link to this post

    Hello Matt,

    Thank you for contacting us.

    In order to show only the Date when using GridViewDateTimeColumn you need to set its FormatString:
    void Form1_Load(object sender, EventArgs e)
    {
        GridViewDateTimeColumn col = this.grid.Columns[0] as GridViewDateTimeColumn;
        col.FormatString = "{0: MM/dd/yyyy}";
    }

    Regarding your other question - our events are very similar to the RoutedEvents in WPF, you can find more information in this article - http://msdn.microsoft.com/en-us/library/ms742806.aspx. The events are also limited to each control, which means that RadGridView cannot notify its parent Form for example. Additionally, you can catch the DoubleClick event in the HostedControl of the editor. You can subscribe to the eventin the CellEditorInitialized event:
    bool subscribed = false;
    void grid_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        if (!subscribed)
        {
            RadDateTimeEditor editor = (RadDateTimeEditor)e.ActiveEditor;
            ((RadDateTimeEditorElement)editor.EditorElement).TextBoxElement.TextBoxItem.HostedControl.MouseDoubleClick += HostedControl_MouseDoubleClick;
            this.subscribed = true;
        }
    }
     
    void HostedControl_MouseDoubleClick(object sender, MouseEventArgs e)
    {
    }

    I hope this information is helpful.
     
    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 >>
  3. MO
    MO avatar
    23 posts
    Member since:
    Jul 2012

    Posted 02 Oct 2013 Link to this post

    I was able to subscribe to the event as you suggested and it worked. However, at what scope do you put the Boolean subscribed? I took your example to mean it should be global, but then it only subscribes to the first cell's event and skips any additional cells (because the Boolean is set to true).

    Putting inside the CellEditorInitialized method simply resets it every time and it tries to subscribe when it is run (which you would think normally isn't a big deal, but apparently it re-runs when you add or remove rows).

  4. George
    Admin
    George avatar
    500 posts

    Posted 07 Oct 2013 Link to this post

    Hello Matt,

    Thank you for replying.

    Yes, the boolean should be global since we want to subscribe only the first time the editor is initialized. Since it is being reused, we do not need to subscribe every time. If using a boolean variable is not a suitable solution for you, you can always unsubscribe for the event first and then subscribe:
    void grid_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
            RadDateTimeEditor editor = (RadDateTimeEditor)e.ActiveEditor;
            ((RadDateTimeEditorElement)editor.EditorElement).TextBoxElement.TextBoxItem.HostedControl.MouseDoubleClick -= HostedControl_MouseDoubleClick;
            ((RadDateTimeEditorElement)editor.EditorElement).TextBoxElement.TextBoxItem.HostedControl.MouseDoubleClick += HostedControl_MouseDoubleClick;
         
    }

    I hope this helps.

    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 >>
Back to Top