问题
I use Xtragrid. I would like to change the default popupmenu columnmenu GridViewColumnMenu and add ColorPieker and FontEditor to change color of cells in the Column and font of the column. Add to the standard menu column two editors have failed. More precisely, the menu items were added, but by clicking on them, nothing happens. I also tried to add all of the standard menu items to menu with the editors, and display it all in barmanager. In this case, working as editor of color and font selection, but the standard menu(GridViewColumnMenu) items dont work
if (e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Column)
{
DevExpress.XtraGrid.Menu.GridViewColumnMenu menu = e.Menu as GridViewColumnMenu;
// menu.Items.Clear();//Erasing the default menu items
if (menu.Column != null)
{
ClickedColumn = "";
ClickedColumn = menu.Column.FieldName;
DXPopupMenu dxPopupMenu = new DXPopupMenu();
dxPopupMenu.Items.Add(new DXEditMenuItem("Color",
new RepositoryItemColorEdit(),
new EventHandler(OnColumnsColorChanged),
null, null, 100, 0));
dxPopupMenu.Items.Add(new DXEditMenuItem("Font",
new RepositoryItemFontEdit(),
new EventHandler(OnColumnsFontChanged),
null, null, 100, 0));
DXPopupMenu sub = new DXPopupMenu();
sub.Caption = "FixedStyle";
sub.Items.Add(CreateCheckItem("Fixed None", menu.Column, FixedStyle.None, null));
sub.Items.Add(CreateCheckItem("Fixed Left", menu.Column, FixedStyle.Left, null));
sub.Items.Add(CreateCheckItem("Fixed Right", menu.Column, FixedStyle.Right, null));
dxPopupMenu.Items.Add(sub);
/*
DXPopupMenu dx = new DXPopupMenu();
dx.Caption = "dx";
foreach (DXMenuItem item in menu.Items)
{
dx.Items.Add(item);
}
//dxPopupMenu.Items.Add(dx);
*/
menu.Items.Clear();
Point p = e.Point;
// p.X += 210;
dxPopupMenu.MenuViewType = MenuViewType.Menu;
((IDXDropDownControl)dxPopupMenu).Show(barManager1, this, p);
Tried to display and menus and menu editors barmanager simultaneously, it all works. But it is not so easy sometimes menus overlap each other.
回答1:
I'm a bit late, but if you still need help, here is what you have to do:
- Handle the GridView's PopupMenuShowing event, and check if e.MenuType is equal to GridMenuType.Column.
- Cast the e.Menu object to GridViewColumnMenu, then you have access to its Column property, which refers to the menu triggering column. Also, you can access now to the Items collection of the menu.
- Create a new DXEditMenuItem object, in its constructor you can set its caption, and any RepositoryItem (editor template) to embed into it (in your case for example a color editor). In the constructo you have to specify an eventhandler for the item's EditValueChanged event as well.
- Assign the Column object to the DXEditMenuItem's Tag property to be able to get it back when you handle the items Click event. Add the item to the menu's Items collection.
- Create the eventhandler. Inside it you can cast the sender object to the DXEditMenuItem which fired the event, and then you can read its EditValue, and also the TAg which holds your Column object. There you can do whatever manipulation you need.
来源:https://stackoverflow.com/questions/14028338/how-to-add-to-the-gridviewcolumnmenu-color-und-font-editors