开发者

How do I get a context menu to work on a Telerik RadGridView column?

开发者 https://www.devze.com 2022-12-16 14:54 出处:网络
I have the following method which adds a new column to a Telerik RadGridView: private void CreateNewColumn(FieldDescriptor fd, uint fieldno) {

I have the following method which adds a new column to a Telerik RadGridView:

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() {
            Tag = fieldno,
            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_Exec开发者_Python百科ute) }
                }
            }
        }
    });
}

The problem I'm having is that the context menu never appears when I right click anywhere on the grid. If I bind the context menu directly to the grid, i.e.

fieldGrid.ContextMenu = new ContextMenu() { ...

then the context menu shows up, but I have no way of determining which column the user right-clicked on. Has anyone gotten context menus to work on individual columns or column headers?


I cannot speak for Telerik's grid, but with the Infragistics grid you would attach the context menu to the grid, and then use the mouse location to determine what the user right clicked on in the grid. The Infragistics grid has some decent helper methods to facilitate the hit testing.


You can check my answer on your forum post: http://www.telerik.com/community/forums/wpf/gridview/column-contextmenu.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消