Skip to content

Commit

Permalink
Merge pull request #481 from telerik/dkrastev/m-pivot-update
Browse files Browse the repository at this point in the history
PivotGrid: Update Code Snippet
  • Loading branch information
nade7o authored Jan 3, 2024
2 parents afbae20 + 6847d97 commit db0f973
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions controls/pivotgrid/context-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ End Sub
````C#
public class MyPivotGridContextMenu : PivotGridContextMenu
{
public MyPivotGridContextMenu(RadPivotGrid pivotGrid)
: base(pivotGrid.PivotGridElement)
{ }
public MyPivotGridContextMenu(RadPivotGrid pivotGrid) : base(pivotGrid.PivotGridElement)
{
}

protected override void AdjustItemsForContext()
{
base.AdjustItemsForContext();

if (this.Context is PivotCellElement)
{
RadMenuItem customMenuItem = new RadMenuItem();
Expand All @@ -68,32 +70,50 @@ public class MyPivotGridContextMenu : PivotGridContextMenu
this.Items.Add(customMenuItem);
}
}

private void customMenuItem_Click(object sender, EventArgs e)
{
RadMessageBox.Show("Export to Excel");
RadMenuItem item = sender as RadMenuItem;

if (this.Context is PivotCellElement)
{
PivotCellElement pivotCell = this.Context as PivotCellElement;
RadPivotGrid pivot = pivotCell.ElementTree.Control as RadPivotGrid;
RadMessageBox.Show("Export to Excel");
}
}
}

````
````VB.NET
Public Class MyPivotGridContextMenu
Inherits PivotGridContextMenu
Public Sub New(pivotGrid As RadPivotGrid)

Public Sub New(ByVal pivotGrid As RadPivotGrid)
MyBase.New(pivotGrid.PivotGridElement)
End Sub

Protected Overrides Sub AdjustItemsForContext()
MyBase.AdjustItemsForContext()

If TypeOf Me.Context Is PivotCellElement Then
Dim customMenuItem As New RadMenuItem()
Dim customMenuItem As RadMenuItem = New RadMenuItem()
customMenuItem.Text = "Export to Excel"
Dim separator As New RadMenuSeparatorItem()
Dim separator As RadMenuSeparatorItem = New RadMenuSeparatorItem()
Me.Items.Add(separator)
AddHandler customMenuItem.Click, AddressOf customMenuItem_Click
customMenuItem.Click += AddressOf customMenuItem_Click
Me.Items.Add(customMenuItem)
End If
End Sub
Private Sub customMenuItem_Click(sender As Object, e As EventArgs)
RadMessageBox.Show("Export to Excel")

Private Sub customMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim item As RadMenuItem = TryCast(sender, RadMenuItem)

If TypeOf Me.Context Is PivotCellElement Then
Dim pivotCell As PivotCellElement = TryCast(Me.Context, PivotCellElement)
Dim pivot As RadPivotGrid = TryCast(pivotCell.ElementTree.Control, RadPivotGrid)
RadMessageBox.Show("Export to Excel")
End If
End Sub
End Class

Expand Down

0 comments on commit db0f973

Please sign in to comment.