GrapeCity MultiRow Windows Forms Documentation
GcMultiRow Property (ListBoxEditingControl)
Example 


Gets or sets the GcMultiRow that hosts this editing control.
Syntax
Public Property GcMultiRow As GcMultiRow
Dim instance As ListBoxEditingControl
Dim value As GcMultiRow
 
instance.GcMultiRow = value
 
value = instance.GcMultiRow
public GcMultiRow GcMultiRow {get; set;}

Property Value

A GcMultiRow that hosts this editing control.
Remarks
This property is automatically set when a Cell enters editing mode.
Example
The following code example shows how to use this property in a custom editing control. This code example is part of a larger example provided for the IEditingControl class.
public class ListBoxEditingControl : ListBox, IEditingControl
{
    public ListBoxEditingControl()
    {
        this.BorderStyle = BorderStyle.None;
    }

    private GcMultiRow _gcMultiRow;

    // MultiRow control will set this property when editing begins. Editing control can use this property.
    public GcMultiRow GcMultiRow
    {
        get
        {
            return _gcMultiRow;
        }
        set
        {
            _gcMultiRow = value;
        }
    }

    private int _rowIndex;

    // MultiRow control sets this property when editing begins. Editing control can use this property.
    public int RowIndex
    {
        get
        {
            return _rowIndex;
        }
        set
        {
            _rowIndex = value;
        }
    }

    // 1. When editing begins, MultiRow should initial this property.
    // 2. When editing ends, MultiRow uses this property's value as the cell value.
    public object FormattedValue
    {
        get
        {
            return this.Text;
        }
        set
        {
            if (value == null)
            {
                this.Text = string.Empty;
            }
            else
            {
                this.Text = value.ToString();
            }
        }
    }
    
    // When the user press Ctrl and uses the wheel mouse wheel button, MultiRow is zoomed.
    // MultiRow changes this property's value when zooming.
    // EditingControl should do something to fit the new zoom factor, for example, change Font.
    private float _zoomFactor;
    private Font _initializeFont = null;
    public float ZoomFactor
    {
        get
        {
            return _zoomFactor;
        }
        set
        {
            this._zoomFactor = value;

            if (_zoomFactor != 1 && _initializeFont != null)
            {
                this.Font = new Font(_initializeFont.FontFamily, _initializeFont.Size * _zoomFactor);
            }
        }
    }

    public Cursor EditingPanelCursor
    {
        get 
        {
            return Cursors.Default;
        }
    }

    // The keys handled by the editing control.
    public bool WantsInputKey(Keys keyData)
    {
        // The editing control handles up and down keys.
        if (keyData == Keys.Up || keyData == Keys.Down)
        {
            return true;
        }
        return false;
    }

    public void PrepareEditingControlForEdit(bool selectAll)
    {
        // Prepare edit for editing control.
    }

    // Apply style.
    public void ApplyCellStyleToEditingControl(CellStyle cellStyle)
    {
        this.BackColor = Color.FromArgb(255, cellStyle.BackColor);
        this.ForeColor = Color.FromArgb(255, cellStyle.ForeColor);

        _initializeFont = cellStyle.Font;

        if (this._zoomFactor != 1)
        {
            this.Font = new Font(_initializeFont.FontFamily, _initializeFont.Size * _zoomFactor);
        }
    }

    // When the value has been edited, editing control should fire DirtyStateChanged event to notify MultiRow control.
    protected override void OnSelectedIndexChanged(EventArgs e)
    {
        base.OnSelectedIndexChanged(e);

        this.OnDirtyStateChanged(EventArgs.Empty);
    }

    protected virtual void OnDirtyStateChanged(EventArgs e)
    {
        if (this.DirtyStateChanged != null)
        {
            this.DirtyStateChanged(this, e);
        }
    }

    public event EventHandler DirtyStateChanged;
}
Public Class ListBoxEditingControl
    Inherits ListBox
    Implements IEditingControl
    Public Sub New()
        Me.BorderStyle = BorderStyle.None
    End Sub

    Private _gcMultiRow As GcMultiRow

    ' MultiRow control sets this property when edit begins. Editing control can use this property.
    Public Property GcMultiRow() As GcMultiRow Implements IEditingControl.GcMultiRow
        Get
            Return _gcMultiRow
        End Get
        Set(ByVal value As GcMultiRow)
            _gcMultiRow = value
        End Set
    End Property

    Private _rowIndex As Integer

    ' MultiRow control sets this property when edit begins. Editing control can use this property.
    Public Property RowIndex() As Integer Implements IEditingControl.RowIndex
        Get
            Return _rowIndex
        End Get
        Set(ByVal value As Integer)
            _rowIndex = value
        End Set
    End Property

    ' 1. When edit begins, MultiRow should initialize this property.
    ' 2. When edit ends, MultiRow uses this property's value as cell value.
    Public Property FormattedValue() As Object Implements IEditingControl.FormattedValue
        Get
            Return Me.Text
        End Get
        Set(ByVal value As Object)
            If value = Nothing Then
                Me.Text = String.Empty
            Else
                Me.Text = value.ToString()
            End If
        End Set
    End Property

    ' When user presses Ctrl and uses the mouse wheel button, MultiRow is zoomed.
    ' MultiRow will change this property's value when zooming.
    ' EditingControl should do someting to fit the new zoom factor, for example, change Font.
    Private _zoomFactor As Single
    Private _initializeFont As Font = Nothing
    Public Property ZoomFactor() As Single Implements IEditingControl.ZoomFactor
        Get
            Return _zoomFactor
        End Get
        Set(ByVal value As Single)
            Me._zoomFactor = value

            If _zoomFactor <> 1 AndAlso Not _initializeFont Is Nothing Then
                Me.Font = New Font(_initializeFont.FontFamily, _initializeFont.Size * _zoomFactor)
            End If
        End Set
    End Property

    Public ReadOnly Property EditingPanelCursor() As Cursor Implements IEditingControl.EditingPanelCursor
        Get
            Return Cursors.Default
        End Get
    End Property

    ' The keys are handled by the editing control.
    Public Function WantsInputKey(ByVal keyData As Keys) As Boolean Implements IEditingControl.WantsInputKey
        ' The editing control handles up and down keys.
        If keyData = Keys.Up OrElse keyData = Keys.Down Then
            Return True
        End If
        Return False
    End Function

    Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements IEditingControl.PrepareEditingControlForEdit
        ' Prepare editing for the editing control.
    End Sub

    ' Apply style.
    Public Sub ApplyCellStyleToEditingControl(ByVal cellStyle As CellStyle) Implements IEditingControl.ApplyCellStyleToEditingControl
        Me.BackColor = Color.FromArgb(255, cellStyle.BackColor)
        Me.ForeColor = Color.FromArgb(255, cellStyle.ForeColor)

        _initializeFont = cellStyle.Font

        If Me._zoomFactor <> 1 Then
            Me.Font = New Font(_initializeFont.FontFamily, _initializeFont.Size * _zoomFactor)
        End If
    End Sub

    ' When the value has been edited, editing control should fire DirtyStateChanged event to notify MultiRow control.
    Protected Overloads Overrides Sub OnSelectedIndexChanged(ByVal e As EventArgs)
        MyBase.OnSelectedIndexChanged(e)

        Me.OnDirtyStateChanged(EventArgs.Empty)
    End Sub

    Protected Overridable Sub OnDirtyStateChanged(ByVal e As EventArgs)
        RaiseEvent DirtyStateChanged(Me, e)
    End Sub

    Public Event DirtyStateChanged As EventHandler Implements IEditingControl.DirtyStateChanged
End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ListBoxEditingControl Class
ListBoxEditingControl Members

 

 


Copyright © GrapeCity, inc. All rights reserved.