Contextmenu bind to selected value of RadGridView Combobox

3 posts, 0 answers
  1. Marcel
    Marcel avatar
    42 posts
    Member since:
    Jan 2014

    Posted 17 Apr 2016 Link to this post

    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. Marcel
    Marcel avatar
    42 posts
    Member since:
    Jan 2014

    Posted 20 Apr 2016 in reply to Marcel Link to this post

    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

     

  3. Martin
    Admin
    Martin avatar
    160 posts

    Posted 20 Apr 2016 Link to this post

    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.
Back to Top