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

Contextmenu bind to selected value of RadGridView Combobox

2 Answers 68 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 17 Apr 2016, 06:53 AM

Hello,

 

I am working on a gridview with a contextmenu.

For the comboboxes in the gridview I want to add an additional menuitem (beside Add/Delete etc.). In that case I want to do a search on the item thats currently selected in the combobox. I wired up the command to it which works fine, I am now stuck with getting the selected value from the combobox.

I want to use this value to show in my contextmenu, for example "Search Item X", where Item X is the name of the selected item in the combobox, I also want to pass the selected item to my command so I can do the actual search.

I created the code below, but I am getting a binding error stating that SelectedValue can not be found on the GridViewCell. How do I bind to the combobox inside the cell?

<ContextMenu x:Key="frsvGridComboContextMenuArtikelGroep" DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
 
    <!-- Search menu-item-->
    <MenuItem CommandParameter="{Binding Parent.PlacementTarget.SelectedValue, RelativeSource={RelativeSource Self}}"
            Command="{Binding DataContext.SearchArtikelGroepCommand, Source={StaticResource subViewSpy}}" DataContext="{Binding}">
        <MenuItem.Icon>
            <Image Source="/Resources.Icons;Component/16x16/search16.png"/>
        </MenuItem.Icon>
        <MenuItem.Header>
            <MultiBinding Converter="{StaticResource frsvSelectedValueToStringMultiValueConverter}">
                <Binding>
                    <Binding.Source>
                        <sys:String>Filter op</sys:String>
                    </Binding.Source>
                </Binding>
                <Binding Path="PlacementTarget.Text"
        RelativeSource="{RelativeSource  AncestorType=ContextMenu}" />
                <Binding>
                    <Binding.Source>
                        <sys:String>...</sys:String>
                    </Binding.Source>
                </Binding>
            </MultiBinding>
        </MenuItem.Header>
    </MenuItem>
</ContextMenu>

 

Any help would be appreciated.

 

Regards,

 

Marcel

2 Answers, 1 is accepted

Sort by
0
Marcel
Top achievements
Rank 1
answered on 20 Apr 2016, 01:29 PM

Already found a solution, need to bind to Parent.PlacementTarget.Content and then with a converter was able to retrieve the selected item and text from it.

Marcel

 

0
Martin
Telerik team
answered on 20 Apr 2016, 02:28 PM
Hello Marcel,

I am really glad to see that you were able to resolve the issue.
Still, as an alternative solution, you can take a look at the attached sample project which I prepared.

Regards,
Martin Vatev
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Marcel
Top achievements
Rank 1
Answers by
Marcel
Top achievements
Rank 1
Martin
Telerik team
Share this question
or