GrapeCity.Windows.SpreadSheet.UI Namespace > CustomDrawingObject Class : ShowDrawingObjectOnly Property |
'Declaration <System.ComponentModel.DefaultValueAttribute()> Public Property ShowDrawingObjectOnly As System.Boolean
'Usage Dim instance As CustomDrawingObject Dim value As System.Boolean instance.ShowDrawingObjectOnly = value value = instance.ShowDrawingObjectOnly
[System.ComponentModel.DefaultValue()] public System.bool ShowDrawingObjectOnly {get; set;}
true
to only show the drawing object; otherwise, false
.public MainWindow() { InitializeComponent(); GrapeCity.Windows.SpreadSheet.UI.DrawingObjectManager.SetDrawingObjectProvider(this.gcSpreadSheet1, new MyObjectProvider()); this.gcSpreadSheet1.Sheets[0].ConditionalFormats.AddRule(new MyDrawingCell(2, 2)); } public class MyObjectProvider : GrapeCity.Windows.SpreadSheet.UI.IDrawingObjectProvider { #region IDrawingObjectProvider Members public GrapeCity.Windows.SpreadSheet.Data.DrawingObject[] GetDrawingObjects(GrapeCity.Windows.SpreadSheet.Data.Worksheet sheet, int row, int column, int rowCount, int columnCount) { List<GrapeCity.Windows.SpreadSheet.Data.DrawingObject> list = new List<GrapeCity.Windows.SpreadSheet.Data.DrawingObject>(); if (sheet.ConditionalFormats != null) { for (int i = 0; i < sheet.ConditionalFormats.RuleCount; i++) { MyDrawingCell rule = sheet.ConditionalFormats[i] as MyDrawingCell; if (rule != null) { GrapeCity.Windows.SpreadSheet.Data.DrawingObject darwingObject = rule.Evaluate(sheet, row, column, null) as GrapeCity.Windows.SpreadSheet.Data.DrawingObject; if (darwingObject != null) { list.Add(darwingObject); } } } } return list.ToArray(); } #endregion } public class MyDrawingCell : GrapeCity.Windows.SpreadSheet.Data.FormattingRuleBase { public MyDrawingCell() : this(-1, -1) { } public MyDrawingCell(int row, int column) : base(null) { this.Row = row; this.Column = column; } public int Row { get; set; } public int Column { get; set; } protected override GrapeCity.Windows.SpreadSheet.Data.ConditionBase CreateCondition() { return null; } public override object Evaluate(GrapeCity.Windows.SpreadSheet.Data.ICalcEvaluator evaluator, int baseRow, int baseColumn, GrapeCity.Windows.SpreadSheet.Data.IActualValue actual) { if (this.Row == baseRow && this.Column == baseColumn) return new MyButtonCell(baseRow, baseColumn); else return null; } } internal class MyButtonCell : GrapeCity.Windows.SpreadSheet.UI.CustomDrawingObject { private Button button; public override FrameworkElement RootElement { get { if (this.button == null) { this.button = new Button(); // HyperlinkButton(); // this.button.Click += new RoutedEventHandler(this.button_Click); this.button.Content = "Click me!"; } return this.button; } } public MyButtonCell(int row, int column) : base(row, column) { base.ShowDrawingObjectOnly = true; } private void button_Click(object sender, RoutedEventArgs e) { GrapeCity.Windows.SpreadSheet.UI.SpreadView sv = GetSpreadView(this.RootElement); MessageBox.Show("Click " + sv.ActiveSheet.GetValue(this.AnchorRow, this.AnchorColumn)); } private GrapeCity.Windows.SpreadSheet.UI.SpreadView GetSpreadView(DependencyObject e) { var t = e; while (t != null) { t = VisualTreeHelper.GetParent(t); if (t is GrapeCity.Windows.SpreadSheet.UI.SpreadView) { return t as GrapeCity.Windows.SpreadSheet.UI.SpreadView; } } return null; } }
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
Target Platforms: Windows 7, Windows 8 Desktop, Windows Vista SP1 or later, Windows Server 2000, Windows 2000 Professional (SP4), Windows XP (SP2), Windows 2008, Windows 2003 Server (SP1)