Editing
By default, the CanUserEdit property of RadVirtualGrid is set to True, thus the editing mechanism is enabled. In order to disable it, its value needs to be set to False.
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. This means that by default there won't be editor visulized until you create it in the event handler.
Events
The editing events will not be raised when the DataProvider mechanism is used for populating the data of RadVirtualGrid. More information can be found in the Getting Started topic.
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
TextInput: Gets the string containing the entered text when the TextInput event occurs.The value of the property will be equal to the key with which enter mode is entered.
The property of the editor that is being edited needs to be set manually as well.
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;
}
Most input controls (MaskedTextInput, RadNumericUpDown, RadComboBox, etc.) in the Material, Fluent and Transparent themes have an opacity applied. This means that you can see through them which could lead to a visual glitch when used as editors in RadVirtualGrid. To avoid this set the Background property of the editor to a solid color when you create it in the event handler.
EditorValueChanged
This event is triggered each time the underlying property value that is edited has been changed. Its event arguments provide the following information.
ColumnIndex: Provides information regarding the column index of the editor
RowIndex: Provides information regarding the row index of the editor
Value: Provides information regarding the user input.
Example 2: Handling the EditorValueChanged event
private void VirtualGrid_EditorValueChanged(object sender,
Telerik.Windows.Controls.VirtualGrid.CellValueEventArgs e)
{
}
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. The properties of the event arguments are listed below.
ColumnIndex: Provides information regarding the column index of the editor
RowIndex: Provides information regarding the row index of the editor
Value: Provides information regarding the user input.
Example 3: Handling the CellEditEnded event
private void VirtualGrid_CellEditEnded_1(object sender, CellEditEndedEventArgs e)
{
}
Methods
BeginEdit
Puts RadVirtualGrid into edit mode for given cell coordinates. The method will work only if the control is not already in edit mode.
- BeginEdit(int rowIndex, int columnIndex)
CancelEdit
Calling this method causes RadVirtualGrid to cancel the current edit, revert to the original value and exit edit mode.
- CancelEdit()
CommitEdit
Commits the current edit and exits edit mode.
- CommitEdit()
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 rowIndex, int columnIndex, object value)
Example 2: Updating RadVirtualGrid with the modified data
private void VirtualGrid_CellEditEnded(object sender,
Telerik.Windows.Controls.VirtualGrid.CellValueEventArgs e)
{
this.VirtualGrid.PushCellValue(e.RowIndex, e.ColumnIndex, e.Value);
}
EditTriggers
RadVirtualGrid provides a mechanism through which the way the control enters edit mode can be controlled. This is done through the EditTriggers property. It is a flag enumeration that has the following values:
CellClick: A single click will put the cell into edit mode.
CurrentCellClick: A click on the current cell will put it into edit mode.
Default: The default setting which combines the CurrentCellClick, F2 and TextInput values.
F2: Pressing F2 on a cell will put it into edit mode.
None: No action will put the cell in edit mode.
TextInput: Any text input will put the cell into edit mode. When the control is populated with data manually, instead of with DataProvider, the EditorNeeded event will have the TextInput property of the event arguments equal to the key with which enter mode is entered.
Action on LostFocus
The action that RadVirtualGrid takes when its element loses focus can be manipulated through the ActionOnLostFocus property. It has the following three values.
CancelEdit: Cancels the current edit when the focus of the edited field is lost.
CommitEdit: Commits the current edit when the focus of the edited field is lost.
None: No specific action will be taken when the focus of the edited field is lost.