DropDownButton with RadGridView

3 posts, 0 answers
  1. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 08 Dec 2010 Link to this post

    I used a sample project from another post and have a RadGridView as the DropDownContent for a DropDownButton. The Content of the Button is bound to the SeletedItem of the GridView. And I created a ContentTemplate to display a piece of data from the SelectedItem.

    How do I display something (a message that says "Select Source" or something similar) when no item is selected in the GridView. Would I use a TemplateSelector?  If so, How? I'm not sure and I've never used TemplateSelector.

    Here is my scaled down code for my ddb:

    <telerik:RadDropDownButton Width="180" Name="SourcesDropDown"
           Content="{Binding SelectedItem, ElementName=gridView}">
       <telerik:RadDropDownButton.ContentTemplate>
         <DataTemplate>
          <TextBlock Text="{Binding Name}" />
         </DataTemplate>
       </telerik:RadDropDownButton.ContentTemplate>
       <telerik:RadDropDownButton.DropDownContent>
         <telerik:RadGridView ShowGroupPanel="False"
            x:Name="gridView" AutoGenerateColumns="False"
            IsReadOnly="True" IsFilteringAllowed="True"  
            ItemsSource="{Binding Sources, Source={StaticResource References}}"
            Width="450" Height="150">
         <telerik:RadGridView.Columns>...</telerik:RadGridView.Columns>
       </telerik:RadGridView>
     </telerik:RadDropDownButton.DropDownContent>
    </telerik:RadDropDownButton>


    Thanks.
  2. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 08 Dec 2010 Link to this post

    And another question related to this same code. I'd like to bind the SelectedItem of the GridView to a property on my ViewModel (which is the dataContext of a Grid that is up the hierarchy), but I get an error that it can't find the source of the binding (no matter if I use ElementName or RelativeSource), I think it's because the scope is different since it's inside the DropDownContent of the button.

    How do I get the GridView to find the right source, so that my binding works?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 14 Dec 2010 Link to this post

    Hi Rayne,

    Can you please have a look at the attached sample and let us know if this is what you had in mind?

    And just to make a few notes: If you want to display different messages depending on the GridView SelectedItem, you can use a ValueConverer. Also, since you want to bind the GridView SelectedItem property to a property from your view model, it is best to bind the DropDownButton Content to that property as well. This way the content will reflect the initially selected item as well.

    I hope this info will help you.

    Regards,
    Tina Stancheva
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
Back to Top