This sample demonstrates the definition of a user control in order to edit a row in a data table. For example, your user control may have several text boxes, checked list box, radio buttons, or Windows Forms controls that are appropriate for allowing the user to edit the row data. You can implement this user control as a repeater control using three methods in an interface that will allow you to display and edit multiple records in a scrolling window where this user control is displayed multiple times.
The implementation of this functionality uses a grid control in virtual mode with a custom cell type based on the user control.
Features
GenericUserControlCell.cs of the CellUserControl class is derived from the user control and implements the ICellUserControl interface.
The user control that needs to be repeated should be derived from the cell user control class by implementing the ICellUserControl's UserControlSetValues, UserControlGetValues, and UserControlIsModified methods.
UserControlSetValues- Sets values for the user control
UserControlGetValues- Gets values from the user control
UserControlIsModified- Specifies whether the user control’s values have been modified
With this implementation in the SampleUserControl class, the data row values are set to the user control's text boxes (UserControlSetValues), and the text box’s values are saved back to the data row (UserControlGetValues).
The GenericPanelCellModel and the GenericPanelCellRenderer classes are derived from the GridGenericControlCellModel/GridGenericControlCellRenderer classes.
They use two instances of the CellUserControl - they are ActiveControl for active drawing and StaticControl for static drawing.
The Grid Repeater User Control is derived from the user control and uses the Grid Control in a virtual mode in order to display data that is in the sample user control.
It adds a repeater cell to the grid and passes two instances of the cell user control - ActiveControl and StaticControl.
Active and static controls are used in GenericPanelCellRenderer class.
Data from the data row view is initialized to the active control in the renderer’s OnInitialize override and then saved back to the DataRowView in the renderer’s OnSaveChanges override.
The grid listens to the data source’s ListChanged event in order to refresh itself to display the updated values.