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

Column ContextMenu

1 Answer 509 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ferruccio Barletta
Top achievements
Rank 1
Ferruccio Barletta asked on 11 Jan 2010, 08:03 PM
I need to have a context menu on a grid whereby I can determine which column the user right-clicked on. I create the columns dynamically with the following code:

        private void CreateNewColumn(FieldDescriptor fd, uint fieldno) { 
            fieldGrid.Columns.Add(new GridViewDataColumn() { 
                UniqueName = fd.fieldName, 
                Header = fd.displayName, 
                DataMemberBinding = new Binding("Fields[" + fieldno + "]"), 
                ContextMenu = new ContextMenu() { 
                    Items = { 
                        new MenuItem() { 
                            Header = "Field Properties"
                            Command = Commands.FieldProperties, 
                            CommandBindings = { new CommandBinding(Commands.FieldProperties, FieldProperties_Execute) }  
                        }, 
                        new MenuItem() { 
                            Header = "Delete Field"
                            Command = Commands.DeleteField, 
                            CommandBindings = { new CommandBinding(Commands.DeleteField, DeleteField_Execute) } 
                        } 
                    } 
                } 
            }); 
        } 

Unfortunately the popup menu never appears when I right click anywhere on the grid. If I bind the context menu to the grid (i.e. fieldGrid.ContextMenu = new ContextMenu() {...) then the menu pops up, but I have no way to tell what column was clicked. Is there a way to make this work?

Thanks,
Ferruccio


1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Jan 2010, 07:10 AM
Hi Ferruccio,

You can use GetClickedElement<>() similar to this demo:
http://demos.telerik.com/wpf/?GridView/RowContextMenu

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Ferruccio Barletta
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or