Public Sub New()
InitializeComponent()
GrapeCity.Windows.SpreadSheet.UI.DrawingObjectManager.SetDrawingObjectProvider(Me.GcSpreadSheet1, New MyObjectProvider())
Me.GcSpreadSheet1.Sheets(0).ConditionalFormats.AddRule(New MyDrawingCell(2, 2))
End Sub
Public Class MyObjectProvider
Implements GrapeCity.Windows.SpreadSheet.UI.IDrawingObjectProvider
#Region "IDrawingObjectProvider Members"
Public Function GetDrawingObjects(sheet As GrapeCity.Windows.SpreadSheet.Data.Worksheet, row As Integer, column As Integer, rowCount As Integer, columnCount As Integer) As GrapeCity.Windows.SpreadSheet.Data.DrawingObject() Implements GrapeCity.Windows.SpreadSheet.UI.IDrawingObjectProvider.GetDrawingObjects
Dim list As New List(Of GrapeCity.Windows.SpreadSheet.Data.DrawingObject)()
If sheet.ConditionalFormats IsNot Nothing Then
For i As Integer = 0 To sheet.ConditionalFormats.RuleCount - 1
Dim rule As MyDrawingCell = TryCast(sheet.ConditionalFormats(i), MyDrawingCell)
If rule IsNot Nothing Then
Dim darwingObject As GrapeCity.Windows.SpreadSheet.Data.DrawingObject = TryCast(rule.Evaluate(sheet, row, column, Nothing), GrapeCity.Windows.SpreadSheet.Data.DrawingObject)
If darwingObject IsNot Nothing Then
list.Add(darwingObject)
End If
End If
Next
End If
Return list.ToArray()
End Function
#End Region
End Class
Public Class MyDrawingCell
Inherits GrapeCity.Windows.SpreadSheet.Data.FormattingRuleBase
Public Sub New()
Me.New(-1, -1)
End Sub
Public Sub New(row As Integer, column As Integer)
MyBase.New(Nothing)
Me.Row = row
Me.Column = column
End Sub
Public Property Row() As Integer
Get
Return m_Row
End Get
Set(value As Integer)
m_Row = Value
End Set
End Property
Private m_Row As Integer
Public Property Column() As Integer
Get
Return m_Column
End Get
Set(value As Integer)
m_Column = Value
End Set
End Property
Private m_Column As Integer
Protected Overrides Function CreateCondition() As GrapeCity.Windows.SpreadSheet.Data.ConditionBase
Return Nothing
End Function
Public Overrides Function Evaluate(evaluator As GrapeCity.Windows.SpreadSheet.Data.ICalcEvaluator, baseRow As Integer, baseColumn As Integer, actual As GrapeCity.Windows.SpreadSheet.Data.IActualValue) As Object
If Me.Row = baseRow AndAlso Me.Column = baseColumn Then
Return New MyButtonCell(baseRow, baseColumn)
Else
Return Nothing
End If
End Function
End Class
Friend Class MyButtonCell
Inherits GrapeCity.Windows.SpreadSheet.UI.CustomDrawingObject
Private button As Button
Public Overrides ReadOnly Property RootElement() As FrameworkElement
Get
If Me.button Is Nothing Then
Me.button = New Button()
' HyperlinkButton(); //
AddHandler button.Click, AddressOf button_Click
Me.button.Content = "Click me!"
End If
Return Me.button
End Get
End Property
Public Sub New(row As Integer, column As Integer)
MyBase.New(row, column)
MyBase.ShowDrawingObjectOnly = True
End Sub
Private Sub button_Click(sender As Object, e As RoutedEventArgs)
Dim sv As GrapeCity.Windows.SpreadSheet.UI.SpreadView = GetSpreadView(Me.RootElement)
MessageBox.Show("Click " + sv.ActiveSheet.GetValue(Me.AnchorRow, Me.AnchorColumn))
End Sub
Private Function GetSpreadView(e As DependencyObject) As GrapeCity.Windows.SpreadSheet.UI.SpreadView
Dim t = e
While t IsNot Nothing
t = VisualTreeHelper.GetParent(t)
If TypeOf t Is GrapeCity.Windows.SpreadSheet.UI.SpreadView Then
Return TryCast(t, GrapeCity.Windows.SpreadSheet.UI.SpreadView)
End If
End While
Return Nothing
End Function
End Class