Edit this page

Editing

By default, the CanUserEdit property of RadVirtualGrid is set to False, thus the editing mechanism is disabled. In order to enabled it, its value needs to be set to True

As RadVirtualGrid does not utilize data binding for populating and managing its data, it does not provide a default editor. Instead, when the user double clicks to enter edit mode, the EditorNeeded event is raised.

EditorNeeded

Through this event a custom editor for handling the editing operation can be defined. The event arguments expose the following properties:

  • ColumnIndex: Provides information regarding the column index of the editor

  • RowIndex: Provides information regarding the row index of the editor

  • Editor: The control that will be used for the editing operation

  • EditorProperty: The editor's dependency property that is to be edited

The property of the editor that is being edited needs to be set manually as well.

[C#] Example 1: Handling the EditorNeeded event

private void VirtualGrid_EditorNeeded(object sender, 
        Telerik.Windows.Controls.VirtualGrid.EditorNeededEventArgs e)
    {
        TextBox tb = new TextBox();

        e.Editor = tb;
        tb.Text = String.Format("{0}.{1}", e.RowIndex, e.ColumnIndex);
        e.EditorProperty = TextBox.TextProperty;
    }

EditorValueChanged

This event is triggered each time the underlying property value that is edited has been changed. Similarly to the previously discussed EditorNeeded event, the EditorValueChanged's event arguments expose the ColumnIndex and RowIndex properties. Furthermore, they provide information regarding the user input through the Value property.

CellEditEnded

The event is raised when the user ends editing the cell by setting the focus to another element. This is the mechanism through which the data modified through the UI can be synchronized with the underlying data source, as updating the data source will be needed only once when the edit of the cell has ended.

PushCellValue

When an edit is committed, the new property value needs to be manually pushed to the underlying source and to RadVirtualGrid as well. The control exposes the PushCellValue method for updating the UI. The method can be used in conjunction with the aforementioned CellEditEnded event handler. It accepts the following parameters.

  • PushCellValue(int columnIndex, int rowIndex, object value)

[C#] Example 2: Updating RadVirtualGrid with the modified data

private void VirtualGrid_CellEditEnded(object sender, 
        Telerik.Windows.Controls.VirtualGrid.CellValueEventArgs e)
    {
        this.VirtualGrid.PushCellValue(e.ColumnIndex, e.RowIndex, e.Value);
    }

See Also