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

Custom gridview columns

1 Answer 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 11 Aug 2015, 11:45 AM

Hello,

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;
 
    #endregion
     
    #region Constructor
     
    #endregion
     
    #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;
        else
            this.CbOpenDropDownOnFocus = true;
    }
 
    #endregion
 
    #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));
 
    #endregion

 

Thanks in advance.

 

Marcel

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 12 Aug 2015, 02:09 PM
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"
       x:Key="EditorStyle">
    <Setter Property="OpenDropDownOnFocus"
            Value="True"/>
</Style>
<telerik:GridViewComboBoxColumn
    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)
{
    this.clubsGrid.BeginEdit();
}

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,
Stefan
Telerik
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
Tags
GridView
Asked by
Marcel
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or