windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-popupmenushowingeventargs.md
Gets an object that identifies a clicked element.
Namespace : DevExpress.XtraGrid.Views.Grid
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
public GridHitInfo HitInfo { get; }
Public ReadOnly Property HitInfo As GridHitInfo
| Type | Description |
|---|---|
| GridHitInfo |
A GridHitInfo object or its descendant that identifies a clicked element.
|
The HitInfo property allows you to determine the Grid’s visual element for which a popup menu will be displayed.
For instance, to check the type of the clicked element, use the HitTest property provided by the HitInfo object.
Refer to the following help topic for more information: Hit Information.
The following code sample displays a context menu when a user right-clicks the Header Panel Button. The created context menu contains a Column Auto Width button. This menu item toggles the GridOptionsView.ColumnAutoWidth option.
void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
if (e.HitInfo.HitTest == GridHitTest.ColumnButton) {
popupMenu_HeaderButton.Tag = e.HitInfo;
e.ShowCustomMenu(popupMenu_HeaderButton);
}
}
GridHitInfo GetHitInfo(BarItemLink link) {
PopupMenu menu = link.LinkedObject as PopupMenu;
return menu.Tag as GridHitInfo;
}
void barButtonItem_AutoWidth_ItemClick(object sender, ItemClickEventArgs e) {
GridHitInfo info = GetHitInfo(e.Link);
info.View.OptionsView.ColumnAutoWidth = !info.View.OptionsView.ColumnAutoWidth;
if (info.View.OptionsView.ColumnAutoWidth == false)
info.View.BestFitColumns();
}
Private Sub gridView1_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
If e.HitInfo.HitTest = GridHitTest.ColumnButton Then
popupMenu_HeaderButton.Tag = e.HitInfo
e.ShowCustomMenu(popupMenu_HeaderButton)
End If
End Sub
Private Function GetHitInfo(ByVal link As BarItemLink) As GridHitInfo
Dim menu As PopupMenu = TryCast(link.LinkedObject, PopupMenu)
Return TryCast(menu.Tag, GridHitInfo)
End Function
Private Sub barButtonItem_AutoWidth_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
Dim info As GridHitInfo = GetHitInfo(e.Link)
info.View.OptionsView.ColumnAutoWidth = Not info.View.OptionsView.ColumnAutoWidth
If info.View.OptionsView.ColumnAutoWidth = False Then info.View.BestFitColumns()
End Sub
Refer to the following help topic for more information: Custom Context Menus.
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the HitInfo property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-grid-show-context-menu-for-rows/CS/FormGridMenu.cs#L17
if (e.MenuType == GridMenuType.Row) {
popupMenu_Row.Tag = e.HitInfo;
e.ShowCustomMenu(popupMenu_Row);
winforms-grid-show-context-menu-for-rows/VB/FormGridMenu.vb#L18
If e.MenuType = GridMenuType.Row Then
popupMenu_Row.Tag = e.HitInfo
e.ShowCustomMenu(popupMenu_Row)
See Also
PopupMenuShowingEventArgs Class