Click here to Skip to main content
14,029,429 members
Rate this:
 
Please Sign up or sign in to vote.
I have two button inside different columns in data grid view in WPF Application. That data grid view will load from DB. At same time , there will be a Location drop down menu item present in each row. I have five columns and the image shows the contents present in the last two column of my wpf application.

Like this

As we can see in the image, the arrow for the drop down is present in the Location. But when I press it, I do not see the sub menuitems as shown in the xaml code below.
<local:CustomListView.View>
    <GridView AllowsColumnReorder="False">
        <GridViewColumn Header="Car" Width="Auto" 
                        DisplayMemberBinding="{Binding Car}" />
        <GridViewColumn Header="House" Width="Auto" 
                        DisplayMemberBinding="{Binding House}" />
        <GridViewColumn Header="" Width="60">
            <GridViewColumn.CellTemplate>
                <DataTemplate>
                    <MenuItem Header="Location" ToolTip="Click to see info">
                        <MenuItem Header="Start" Click="info_Click" 
                                  ToolTip="Shows the start route"/>
                        <MenuItem Header="Final" Click="info_Click" 
                                  ToolTip="Show the final route"/>
                    </MenuItem>
                </DataTemplate>
            </GridViewColumn.CellTemplate>
        </GridViewColumn> 
    </GridView>
</local:CustomListView.View>
For some reason, I am unable to see the sub-items Start and Final. I am very new to this and would appreciate any help.

Thanks to all.

I am not able to understand how to add the following code section shown below to have a menu item. Is it possible or is there any other approach?
<local:CustomListView.ContextMenu>
    <ContextMenu>    
    //I want to be able to place the MenuItem in here
    </ContextMenu>
</local:CustomListView.ContextMenu>
I want to add something like this in the GridViewColumn.CellTemplate section.

Can someone guide me on how to do this. I have spent hours but with no success.

What I have tried:

The code sections shown above is what I have tried.
Posted
Updated 27-Feb-19 4:08am
v2
Comments
CHill60 27-Feb-19 9:31am
   
You should be aware that you can't paste images into questions here. I don't think you need the image though as you have explained the problem clearly.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You're not clear on "where" this context menu is supposed to go.

Grid? Header? Cell?

In any event, you don't "template a menu". The "cell" has something (e.g. a textblock) to which the menu is attached. In your case, you're not even binding the column to anything.

And toss the "custom" datagrid until you can get a "regular" datagrid to do what you want re: menus.

The WPF ContextMenu - The complete WPF tutorial[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190419.4 | Last Updated 27 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100