Back to Devexpress

WinExplorerView.ContextButtonCustomize Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-winexplorer-dot-winexplorerview-a8246423.md

latest6.5 KB
Original Source

WinExplorerView.ContextButtonCustomize Event

Allows you to customize individual context buttons for specific WinExplorerView items.

Namespace : DevExpress.XtraGrid.Views.WinExplorer

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Context Buttons")]
public event WinExplorerViewContextButtonCustomizeEventHandler ContextButtonCustomize
vb
<DXCategory("Context Buttons")>
Public Event ContextButtonCustomize As WinExplorerViewContextButtonCustomizeEventHandler

Event Data

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

PropertyDescription
ItemGets the currently processed context button.
RowHandleGets the row handle of the currently processed data record.

Remarks

By default, all WinExplorerView items display the same context buttons with equal settings. Handle the ContextButtonCustomize event to override these global settings. Use the e.RowHandle parameter to get the current data row (and thus, the current view item) and e.Item parameter to get and modify the current context button.

The code below hides all context buttons for all view items that represent odd data rows.

csharp
private void winExplorer1_ContextButtonCustomize(object sender, DevExpress.XtraGrid.Views.WinExplorer.WinExplorerContextButtonCustomizeEventArgs e) {
    if (e.RowHandle % 2 == 0) e.Item.Visibility = DevExpress.Utils.ContextItemVisibility.Hidden;
}
vb
Private Sub winExplorer1_ContextButtonCustomize(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.WinExplorer.WinExplorerContextButtonCustomizeEventArgs)
    If e.RowHandle Mod 2 = 0 Then
        e.Item.Visibility = DevExpress.Utils.ContextItemVisibility.Hidden
    End If
End Sub

See the ‘Context Buttons’ section of the WinExplorer View topic for more info.

Example

If the ShowCheckBoxes option is enabled, the view displays check boxes in each record (row). The CheckBoxColumn property specifies the data field (column) that contains values for the check boxes. The code below shows how to use context check buttons instead of check boxes in the view.

csharp
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.WinExplorer;
using DevExpress.XtraGrid.Views.Base;

winExplorerView1.OptionsView.ShowCheckBoxes = false;

private void winExplorerView1_ContextButtonClick(object sender, ContextItemClickEventArgs e) {
    WinExplorerView view = sender as WinExplorerView;
    if (e.Item.Name == "itemCheck") {
        view.SetRowCellValue((int)e.DataItem, view.ColumnSet.CheckBoxColumn, ((CheckContextButton)e.Item).Checked);
    }
}

private void winExplorerView1_ContextButtonCustomize(object sender, WinExplorerViewContextButtonCustomizeEventArgs e) {
    WinExplorerView view = sender as WinExplorerView;
    if (e.Item.Name == "itemCheck") {
        ((CheckContextButton)(e.Item)).Checked = Convert.ToBoolean(view.GetRowCellValue(e.RowHandle, view.ColumnSet.CheckBoxColumn));
    }
}

private void winExplorerView1_CellValueChanged(object sender, CellValueChangedEventArgs e) {
    WinExplorerView view = sender as WinExplorerView;
    if (e.Column == view.ColumnSet.CheckBoxColumn) {
        view.RefreshContextButtons();
    }
}
vb
Imports DevExpress.Utils
Imports DevExpress.XtraGrid.Views.WinExplorer
Imports DevExpress.XtraGrid.Views.Base

winExplorerView1.OptionsView.ShowCheckBoxes = False

Private Sub winExplorerView1_ContextButtonClick(ByVal sender As Object, ByVal e As ContextItemClickEventArgs) _
    Handles winExplorerView1.ContextButtonClick
    Dim view As WinExplorerView = TryCast(sender, WinExplorerView)
    If e.Item.Name = "itemCheck" Then
        view.SetRowCellValue(DirectCast(e.DataItem, Integer), view.ColumnSet.CheckBoxColumn, CType(e.Item, CheckContextButton).Checked)
    End If
End Sub

Private Sub winExplorerView1_ContextButtonCustomize(ByVal sender As Object, ByVal e As WinExplorerViewContextButtonCustomizeEventArgs) _
    Handles winExplorerView1.ContextButtonCustomize

    Dim view As WinExplorerView = TryCast(sender, WinExplorerView)
    If e.Item.Name = "itemCheck" Then
        CType(e.Item, CheckContextButton).Checked = Convert.ToBoolean(view.GetRowCellValue(e.RowHandle, view.ColumnSet.CheckBoxColumn))
    End If
End Sub

Private Sub winExplorerView1_CellValueChanged(ByVal sender As Object, ByVal e As CellValueChangedEventArgs) _
    Handles winExplorerView1.CellValueChanged
    Dim view As WinExplorerView = TryCast(sender, WinExplorerView)
    If e.Column Is view.ColumnSet.CheckBoxColumn Then
        view.RefreshContextButtons()
    End If
End Sub

See Also

WinExplorer View

WinExplorerView Class

WinExplorerView Members

DevExpress.XtraGrid.Views.WinExplorer Namespace