custom new row

4 posts, 0 answers
  1. bkagan98
    bkagan98 avatar
    16 posts
    Member since:
    Feb 2011

    Posted 04 May 2011 Link to this post

    One of my grids has columns with default textboxes and boud to an observable collection data set that comes from wcf service. The question is - when user inserts new record (by pressing 'insert' button), in that new record (in edit mode) how to display comboboxes instead of standard textboxes? I don't see much info in documentation. Please advise. Thanks.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 May 2011 Link to this post

    Hi Boris,

    I am sending you a sample project illustrating how you may achieve the desired result. Generally, the idea to create a new custom control that is aware whether the row is of type GridViewNewRow or GridViewRow and depending on this to display TextBox or RadComboBox.
      

    Kind regards,
    Maya
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. bkagan98
    bkagan98 avatar
    16 posts
    Member since:
    Feb 2011

    Posted 04 May 2011 Link to this post

    Hi Maya,

    Thanks for a sample - works perfectly. However, I have one more question: what should I change in your sample to show same combobox in edit mode also (for existing records)? Please advise. Thanks.
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 05 May 2011 Link to this post

    Hello Boris,

    You may slightly extend the functionality of the SelectiveEditor_Loaded event. As the "parentRow" is the corresponding row, you may get its Item whose type will be your business object. So, you may verify whether a value for a property is equal to the one you want to set the RadComboBox-editor for. 
    For example:

    void SelectiveEditor_Loaded(object sender, RoutedEventArgs e)
            {
                var parentRow = this.ParentOfType<GridViewRow>();
                if (parentRow is GridViewNewRow)
                {
                    this.Combo.Visibility = Visibility.Visible;
                    this.Combo.SetBinding(RadComboBox.SelectedValueProperty, new Binding("Description") { Mode = BindingMode.TwoWay });
                    this.TextBox.Visibility = Visibility.Collapsed;
                     
                }
                else
                {
                    this.Combo.Visibility = Visibility.Collapsed;
                    this.TextBox.Visibility = Visibility.Visible;
     
                    this.Combo.ClearValue(RadComboBox.SelectedValueProperty);
                }
                if((parentRow.Item as Item).Description == "one")
                {
                    this.Combo.Visibility = Visibility.Visible;
                    this.Combo.SetBinding(RadComboBox.SelectedValueProperty, new Binding("Description") { Mode = BindingMode.TwoWay });
                    this.TextBox.Visibility = Visibility.Collapsed;
                }
                else
                {
                    this.Combo.Visibility = Visibility.Collapsed;
                    this.TextBox.Visibility = Visibility.Visible;
     
                    this.Combo.ClearValue(RadComboBox.SelectedValueProperty);
                }
            }

    In the case above if the value of "Description" property is "one", the editor will be a RadComboBox, otherwise - a plain TextBox.


    Greetings,
    Maya
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
Back to Top