Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
<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?
C#
<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

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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900