DataFormComboBoxField allow nulls

8 posts, 1 answers
  1. Curt
    Curt avatar
    14 posts
    Member since:
    Jan 2012

    Posted 30 Mar 2012 Link to this post

    My combo is configured in the form's AutoGeneratingField event:
    e.DataField = new DataFormComboBoxField()
    {
        Label = "My combo",
        ItemsSource = ComboTypeList.comboTypes,
        DataMemberBinding = new Binding("FieldName")
        {
            ValidatesOnExceptions = true,
            NotifyOnValidationError = true,
            Mode = BindingMode.TwoWay
        }
    }

    I would like my combo to show the "Clear Selection" button, but do not know how to access the property.

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 31 Mar 2012 Link to this post

    Hello Curt,

    You can create implicit style targeting RadComboBox and define its clear selection button. For example:

    <UserControl.Resources>    
        <Style TargetType="telerik:RadComboBox">
            <Setter Property="ClearSelectionButtonContent" Value="Clear me" />
            <Setter Property="ClearSelectionButtonVisibility" Value="Visible" />
        </Style>
    </UserControl.Resources>

    This style will be applied to each of the combo boxes in your application.

    Kind regards,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Curt
    Curt avatar
    14 posts
    Member since:
    Jan 2012

    Posted 02 Apr 2012 Link to this post

    Maya

    I don't think that solution will work in my situation.
    Defining a style for a RadComboBox doesn't apply to a DataFormComboBoxField.
    Any other ideas?

    Thanks
  5. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Apr 2012 Link to this post

    Hi Curt,

    I am sending you a sample project illustrating the suggested approach. Could you take a look at it and let me know if it will work for you ?  

    Regards,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Curt
    Curt avatar
    14 posts
    Member since:
    Jan 2012

    Posted 03 Apr 2012 Link to this post

    Maya
    Your technique works fine in the sample, and I marked your post as an answer.
    I need to modify my project to use your technique.
    Thanks
  7. Oystein
    Oystein avatar
    1 posts
    Member since:
    May 2013

    Posted 12 Jun 2013 Link to this post

    Sorry for replying to such an old thread.
    I solved the problem mentioned by overriding the GetControl() method in the DataFormComboboxField class.

    public class DataFormClearableComboBoxField : DataFormComboBoxField
    {
        public DataFormClearableComboBoxField() : base() { }
     
        protected override Control GetControl()
        {
            var cBox = (RadComboBox)base.GetControl();
            cBox.ClearSelectionButtonVisibility = System.Windows.Visibility.Visible;
            cBox.ClearSelectionButtonContent = "Clear selection";
            return cBox;
        }
    }
  8. Peter
    Peter avatar
    37 posts
    Member since:
    Dec 2011

    Posted 27 Jan 2014 in reply to Maya Link to this post

    Hi Maya,

    your solution is only viable if all ComboBoxes in the RadDataForm should show the ClearSelectionButton or all should hide this button. 

    But there are cases when the user wants to show the ClearSelectionButton only for some of the properties beeing displayed. Unfortunately there seems to be no way to show or hide the button in the Autogenerator. There is noting like 

    DataFormComboBoxField.ClearSelectionButtonVisibility  or
    DataFormComboBoxField.ContentStyle to modify the appearance of the RadComboBoxes

    I have taken Oystein's proposal and derived an extended DataFormComboBoxField class to use in the autogenerator. 

    Is there no more elegant way?

    (See also my question http://www.telerik.com/forums/modify-appearance-of-radcomboboxes-in-raddataform)
     
    /// <summary>
    /// This class extends Telerik's DataFormComboBoxField, allowing to modify ClearSelectionButton's visibility.
    /// This solves the problem, that in the autogenerator the underlying RadComboBox is not accessible and therefore it is not
    /// possible to hide or show the ClearSelectionButton from the autogerator.
    /// </summary>
    public class DataFormComboBoxFieldEx
        :
        DataFormComboBoxField
    {
        public DataFormComboBoxFieldEx() : base() { }
     
        // Set this field to show or hide the ClearSelectionButton
        public System.Windows.Visibility ClearSelectionButtonVisibility = System.Windows.Visibility.Visible;
     
        protected override Control GetControl()
        {
            RadComboBox cBox = (RadComboBox)base.GetControl();
            cBox.ClearSelectionButtonVisibility = ClearSelectionButtonVisibility;
            return cBox;
        }
    }


  9. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 29 Jan 2014 Link to this post

    Hi Peter,

    I have already answered your ticket containing the same question.

    Regards,
    Yoan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    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
DevCraft banner