Search Menu
- 2 minutes to read
The ribbon can display a search box that allows a user to find a bar item by its caption.
To display the search box, set the ShowSearchItem property to true
.
Bar Items in the Menu
Bar items are found by their captions and search tags. If you want a specific bar item not to appear in the search menu, set its VisibleInSearchMenu property to false
.
using DevExpress.XtraBars;
BarButtonItem closeButton = new BarButtonItem();
closeButton.Caption = "Close";
closeButton.SearchTags = "Quit, Exit";
closeButton.ItemClick += CloseButton_ItemClick;
ribbonControl1.Items.Add(closeButton);
ribbonPageGroup1.ItemLinks.Add(closeButton);
private void CloseButton_ItemClick(object sender, ItemClickEventArgs e) {
this.Close();
}
Customize the Menu
The CustomizeSearchMenu event fires when the query in the search box changes, and allows you to customize the menu. The following properties provide information specific to this event:
SearchString
- gets the search query;Menu
- gets the search menu (see PopupMenu).
The code below shows how to add a custom button to the menu.
using DevExpress.XtraBars;
ribbonControl1.CustomizeSearchMenu += RibbonControl1_CustomizeSearchMenu;
BarButtonItem shareButton;
BarButtonItem ShareButton {
get {
if (shareButton == null) {
BarButtonItem shareButton = new BarButtonItem();
shareButton.Caption = "Share";
shareButton.ItemClick += (s, e) => MessageBox.Show("Share");
shareButton.Manager = ribbonControl1.Manager;
this.shareButton = shareButton;
}
return shareButton;
}
}
private void ribbonControl1_CustomizeSearchMenu(object sender, DevExpress.XtraBars.Ribbon.RibbonSearchMenuEventArgs e) {
e.Menu.AddItem(ShareButton);
}