Custom gridview columns

2 posts, 0 answers
  1. Marcel
    Marcel avatar
    42 posts
    Member since:
    Jan 2014

    Posted 11 Aug 2015 Link to this post


    I want to override some functionality of the GridView combobox, datepicker and data column.

    I overriden the class GridViewComboBoxColumn, but the functionality is not working.

    My goal is for the combobox, when it receives focus it should show the dropdown, the user can then select the value with one enter and control should automatically move to the next field in the GridView.

    The same functionality I want to implement for the DatePicker. And for the Textbox I want the enter function like the tab.

    public class CustomGridViewComboBoxColumn : GridViewComboBoxColumn
        #region Fields
        private bool _isEnterInThisCombo = false;
        #region Constructor
        #region Methods
        private void ComboBox_PreviewKeyUp(object sender, KeyEventArgs e)
            if (e.Key == Key.Enter && _isEnterInThisCombo)
                if(this.IsVmEditMode && ! Validation.GetHasError(this))
                    CbIsCheckedForAudit = true;
                this.MoveFocus(new TraversalRequest(System.Windows.Input.FocusNavigationDirection.Next));
                /* Reset flag */
                _isEnterInThisCombo = false;
        private void ComboBox_PreviewKeyDown(object sender, KeyEventArgs e)
            if (e.Key == Key.Enter)
                _isEnterInThisCombo = true;
        private void ComboBox_Loaded(object sender, RoutedEventArgs e)
            if (this.IsVmEditMode) // && this.SelectedValue == null)
                this.CbOpenDropDownOnFocus = true;
            else if (this.IsVmEditMode)
                this.CbOpenDropDownOnFocus = false;
                this.CbOpenDropDownOnFocus = true;
        #region Dependency Properties
        public bool CbOpenDropDownOnFocus
            get { return (bool)GetValue(CbOpenDropDownOnFocusProperty); }
            set { SetValue(CbOpenDropDownOnFocusProperty, value);}
        public static readonly DependencyProperty CbOpenDropDownOnFocusProperty =
            DependencyProperty.Register("CbOpenDropDownOnFocus", typeof(bool), typeof(CustomGridViewComboBoxColumn), new PropertyMetadata(false));
        public bool CbIsCheckedForAudit
            get { return (bool)GetValue(CbIsCheckedForAuditProperty); }
            set { SetValue(CbIsCheckedForAuditProperty, value); }
        public static readonly DependencyProperty CbIsCheckedForAuditProperty =
            DependencyProperty.Register("CbIsCheckedForAudit", typeof(bool), typeof(CustomGridViewComboBoxColumn), new PropertyMetadata(false));
        public virtual bool IsVmEditMode
            get { return (bool)GetValue(IsVmEditModeProperty); }
            set { SetValue(IsVmEditModeProperty, value); }
        public static readonly DependencyProperty IsVmEditModeProperty =
            DependencyProperty.Register("IsVmEditMode", typeof(bool), typeof(CustomGridViewComboBoxColumn), new PropertyMetadata(false));


    Thanks in advance.



  2. Stefan
    Stefan avatar
    1073 posts

    Posted 12 Aug 2015 Link to this post

    Hi Marcel,

    Let me propose you a slightly different approach for this customizations.

    GridViewComboBoxColumn uses RadComboBox control as its editor. So, instead of implementing a custom column, you can benefit from the built-in OpenDropDownOnFocus property of RadComboBox by setting it through Style for GridViewComboBoxColumn editor:
    <Style TargetType="telerik:RadComboBox"
        <Setter Property="OpenDropDownOnFocus"
        EditorStyle="{StaticResource EditorStyle}"/>

    One more thing to do is to force RadGridView to enter edit mode when RadComboBox gets focus:
    this.AddHandler(RadComboBox.GotFocusEvent, new RoutedEventHandler(OnGotFocus));
    private void OnGotFocus(object sender, RoutedEventArgs e)

    I am sorry, but as already replied in the popup calendar when gotfocus forum thread, RadDateTimePicker does not currently support such functionality.

    As for the TextBox control, you can take a look at the Keyboard Command Provider topic. It demonstrates how to customize which command RadGridView to execute on a particular key press.

    Hope this helps.

    Best Regards,
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top