GrapeCity MultiRow Windows Forms Documentation
IEditingControl Interface
Members  Example 


Defines common functionality for controls that are hosted within cells of a GcMultiRow control.
Object Model
IEditingControl InterfaceGcMultiRow Class
Syntax
<EditorBrowsableAttribute(EditorBrowsableState.Advanced)>
Public Interface IEditingControl 
Dim instance As IEditingControl
[EditorBrowsable(EditorBrowsableState.Advanced)]
public interface IEditingControl 
Remarks

Cell types that display an editing control when the cell is in edit mode, such as TextBoxCell, do not implement IEditingCell but instead provide a companion class that implements IEditingControl. For example, TextBoxCell provides a TextBoxEditingControl that derives from the System.Windows.Forms.TextBox control and implements IEditingControl. In this case, the cell's Cell.EditType property is set to a Type object representing the editing control type. GcMultiRow creates an instance based on the cell's Cell.EditType property when the Cell hosts an editing control for the first time. Then the cells with the same Cell.EditType property use the editing control that has been created.

Cell types that display a cell when the cell is in edit mode, such as CheckBoxCell, do not implement IEditingControl but instead provide a companion class that implements IEditingCell. The class derives from Cell and provides a user interface (UI) for specifying values without hosting an editing control. In this case, the cell EditType property is set to a null reference (Nothing in Visual Basic).

Other cell types, such as ButtonCell, provide a UI but do not store user-specified values. In this case, the cell type does not implement IEditingCell or host an editing control.

Example
The following code example shows how to customize an editing control for a cell. You can double-click a cell and select an item in the list box control to edit a cell's value.
public class ListBoxCell : Cell
    {
        public override Type EditType
        {
            get
            {
                return typeof(ListBoxEditingControl);
            }
        }

        List<string> _items = new List<string>();

        public List<string> Items
        {
            get
            {
                return _items;
            }
        }

        protected override void InitializeEditingControl(int rowIndex, object formattedValue, CellStyle style)
        {
            // Apply the cell settings to editing control. 
            base.InitializeEditingControl(rowIndex, formattedValue, style);

            ListBoxEditingControl listBoxEditingControl = this.GcMultiRow.EditingControl as ListBoxEditingControl;

            for (int i = 0; i < this._items.Count; i++)
            {
                listBoxEditingControl.Items.Add(this._items[i]);
            }

            listBoxEditingControl.FormattedValue = formattedValue;
        }

        protected override void TerminateEditingControl(int rowIndex)
        {
            ListBoxEditingControl listBoxEditingControl = this.GcMultiRow.EditingControl as ListBoxEditingControl;
            
            // For performance reasons, MultiRow uses the same instance for all cells.
            // When leaving edit mode, clear items to prepare editing control for use next time.
            listBoxEditingControl.Items.Clear();

            base.TerminateEditingControl(rowIndex);
        }

        public override object Clone()
        {
            // When you derive from Cell and add new properties to the derived class, be sure to
            // override the Clone method to copy the new properties during cloning operations. 
            // You should also call the base class's Clone method so that the properties of the 
            // base class are copied to the new cell. 
            ListBoxCell listBoxCell = base.Clone() as ListBoxCell;

            listBoxCell.Items.AddRange(this.Items);

            return listBoxCell;
        }
    }
Public Class ListBoxCell
    Inherits Cell
    Public Overloads Overrides ReadOnly Property EditType() As Type
        Get
            Return GetType(ListBoxEditingControl)
        End Get
    End Property

    Private _items As New List(Of String)()

    Public ReadOnly Property Items() As List(Of String)
        Get
            Return _items
        End Get
    End Property

    Protected Overloads Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal formattedValue As Object, ByVal style As CellStyle)
        ' Apply the cell settings to editing control. 
        MyBase.InitializeEditingControl(rowIndex, formattedValue, style)

        Dim listBoxEditingControl As ListBoxEditingControl = TryCast(Me.GcMultiRow.EditingControl, ListBoxEditingControl)


        For i As Integer = 0 To Me._items.Count - 1
            listBoxEditingControl.Items.Add(Me._items(i))
        Next

        listBoxEditingControl.FormattedValue = formattedValue
    End Sub

    Protected Overloads Overrides Sub TerminateEditingControl(ByVal rowIndex As Integer)
        Dim listBoxEditingControl As ListBoxEditingControl = TryCast(Me.GcMultiRow.EditingControl, ListBoxEditingControl)

        ' For performance reasons, MultiRow uses the same instance for all cells.
        ' When leaving edit mode, clear items to prepare the editing control for use next time.
        listBoxEditingControl.Items.Clear()

        MyBase.TerminateEditingControl(rowIndex)
    End Sub

    Public Overloads Overrides Function Clone() As Object
        ' When you derive from Cell and add new properties to the derived class, be sure to
        ' override the Clone method to copy the new properties during cloning operations. 
        ' You should also call the base class's Clone method so that the properties of the 
        ' base class are copied to the new cell. 
        Dim listBoxCell As ListBoxCell = TryCast(MyBase.Clone(), ListBoxCell)

        listBoxCell.Items.AddRange(Me.Items)

        Return listBoxCell
    End Function
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

IEditingControl Members
GrapeCity.Win.MultiRow Namespace
ComboBoxEditingControl Class
DateTimePickerEditingControl Class
DomainUpDownEditingControl Class
MaskedTextBoxEditingControl Class
NumericUpDownEditingControl Class
PopupEditingControl Class
RichTextBoxEditingControl Class
TextBoxEditingControl Class

 

 


Copyright © GrapeCity, inc. All rights reserved.