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

DropDownButton with RadGridView

2 Answers 256 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Rayne
Top achievements
Rank 1
Rayne asked on 08 Dec 2010, 09:51 PM
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 Answers, 1 is accepted

Sort by
0
Rayne
Top achievements
Rank 1
answered on 08 Dec 2010, 11:31 PM
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?
0
Tina Stancheva
Telerik team
answered on 14 Dec 2010, 11:05 AM
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
Tags
Buttons
Asked by
Rayne
Top achievements
Rank 1
Answers by
Rayne
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or