Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Preventing users from typing in a date (pick from calendar only)
posted

This is probably an easy solution but I've delved into the column properties and can't see a way to acheive this:

I have a regular WinGrid (Win Client 2008 Vol. 3) bound to a typed dataset with several date columns.  I do NOT need to specify that the date columns should display the calendar control for editing - this is done automatically since the grid knows that the column is of a datetime data type.

However, is there a way to set up the column so that users have to choose a date from the calendar control, instead of also being able to type in a date in that column? 

TIA.

Parents
No Data
Reply
  • 69832
    Suggested Answer
    Offline posted

    I don't believe there is a column style (see UltraGridColumn.Style) that supports displaying a calendar dropdown while at the same disallowing keyboard entry; if you like you can submit a feature request for that functionality. In the meantime, you could handle the KeyPress event and eat all alpha-numeric keys, like so:

    void UltraGrid_KeyPress(object sender, KeyPressEventArgs e)
    {
        UltraGrid grid = sender as UltraGrid;
        UltraGridCell activeCell = grid.ActiveCell;
        if ( activeCell != null &&
             activeCell.Column.DataType != null &&
             activeCell.Column.DataType.IsAssignableFrom(typeof(DateTime)) )
            e.Handled = true;
    }

Children
No Data