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:
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
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