Back to Devexpress

RibbonControl.CustomizeSearchMenu Event

windowsforms-devexpress-dot-xtrabars-dot-ribbon-dot-ribboncontrol-22416473.md

latest6.4 KB
Original Source

RibbonControl.CustomizeSearchMenu Event

Fires when the query in the search box changes and allows you to customize search results.

Namespace : DevExpress.XtraBars.Ribbon

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event RibbonSearchMenuEventHandler CustomizeSearchMenu
vb
<DXCategory("Events")>
Public Event CustomizeSearchMenu As RibbonSearchMenuEventHandler

Event Data

The CustomizeSearchMenu event's data class is RibbonSearchMenuEventArgs. The following properties provide information specific to this event:

PropertyDescription
MenuGets the search menu.
SearchStringGets text entered in the search box. Inherited from RibbonSearchMenuBaseEventArgs.
ShowNoMatchesItemGets or sets whether to display the No matches found item in the Search Menu.

The event data class exposes the following methods:

MethodDescription
AddHeader(String)Adds a header to the Search Menu.
AddItem(BarItem)Adds an item to the Search Menu.

Remarks

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:

Enable the RibbonOptionsSearchMenu.UseCustomRibbonSearch option to populate the search menu only through the CustomizeSearchMenu event.

Example

The code below shows how to add a custom button to the menu and show an item regardless of the current query.

csharp
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) {
    // Add a custom button that is always visible.
    e.AddItem(ShareButton);
    // Show the Online Help command regardless of the current query.
    e.Menu.ItemLinks.Where(x => x.Item == biOnlineHelp).First().Visible = true;
}
vb
Imports DevExpress.XtraBars

Private shareButton1 As BarButtonItem
Private ReadOnly Property ShareButton() As BarButtonItem
    Get
        If shareButton1 Is Nothing Then
            Dim share As New BarButtonItem()
            share.Caption = "Share"
            AddHandler share.ItemClick, Sub(s, e) MessageBox.Show("Share")
            shareButton1.Manager = ribbonControl1.Manager
            Me.shareButton1 = share
        End If
        Return shareButton1
    End Get
End Property

Private Sub ribbonControl1_CustomizeSearchMenu(ByVal sender As Object, ByVal e As Ribbon.RibbonSearchMenuEventArgs) _
    Handles ribbonControl1.CustomizeSearchMenu
    ' Add a custom button that is always visible.
    e.AddItem(ShareButton)
    ' Show the Online Help command regardless of the current query.
    e.Menu.ItemLinks.Where(Function(x) x.Item Is biOnlineHelp).First().Visible = True
End Sub

See Also

Search Menu

SearchItemPosition

SearchTags

VisibleInSearchMenu

RibbonControl Class

RibbonControl Members

DevExpress.XtraBars.Ribbon Namespace