set ClearSelectionButtonVisibilityProperty in code behind

3 posts, 0 answers
  1. Martin
    Martin avatar
    4 posts
    Member since:
    Sep 2011

    Posted 13 Mar 2013 Link to this post

    Hi Guys!

    Please help me.

    I am building a radGridView dynamically from a Databasetable.
    So the GridColumns are not defined in XAML.

    This dynamically GridView might have some GridViewComboBoxColumns
    and the user should be able to delete/deselect the value.

    I am trying this in the code behind:

                        GridViewComboBoxColumn ComboBoxCol = new GridViewComboBoxColumn();
                        ComboBoxCol.SetValue(RadComboBox.ClearSelectionButtonVisibilityProperty, "Visible");
                        ComboBoxCol.SetValue(RadComboBox.ClearSelectionButtonContentProperty, null);

    But I get a runtime error, that "Visible" is no valid value for the property.

    Any suggestions?


    Thanks and Regards, Martin



  2. Martin
    Martin avatar
    4 posts
    Member since:
    Sep 2011

    Posted 14 Mar 2013 Link to this post


    Well,... Thinking a bit for myself and using the debugger I found my Error.
    (A full night of sleep, might also have done the miracle ;-) )

    The following is partially working:

    ComboBoxCol.SetValue(RadComboBox.ClearSelectionButtonVisibilityProperty, System.Windows.Visibility.Visible);

    My "only" problem now is, that the ClearButton is not showing.
    The property ist set to visible but control is not showing.

    Any suggestions?

    Thanks and my best regards, Martin
  3. Yoan
    Admin
    Yoan avatar
    1182 posts

    Posted 15 Mar 2013 Link to this post

    Hello Martin,

    In order to achieve your goal you will have to inherit  the GridViewComboBoxColumn and override the CreateCellElement method.

    However, the easiest way to accomplish this would be to create implicit style targeting RadComboBox, like so:

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

    This style will be applied to each of the combo boxes in your application.
    You can take a look at this forum thread for a reference as well.

    Greetings,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top