Hide

SftTree/NET 2.0 - Tree Control for Windows Forms

Display
Print

Cell Editing

SftTree/NET supports most controls for cell editing, text box, combo box, etc., even UserControls and ActiveX controls. SftTree/NET offers a simple, yet powerful approach to cell editing. The application retains control and ownership of all controls used for cell editing. All their properties can usually be defined at design-time, even using their property pages, if available.

In order to use a control for cell editing, it is simply added to the form that also contains the tree control (they are not added to the tree control, but to the containing form). Because only one cell can be edited at a time, only one control is needed for the entire tree control. Of course, it is also possible to use several different types of controls, an edit control for some cells and a combo box control for others. One of each control type is added to the form.

When cell editing is started using the CellClass.Edit method, a number of events occur that are used to position the control used for cell editing, initialize its contents and prepare it for editing. The EditAllowed event immediately occurs to check whether the cell can be edited.

Then, the EditSetup event occurs. It is used to make a control for cell editing available, by returning a control window in the EditSetupEventArgs.EditControl field. The control's display attributes and contents are initialized by this event and it is sized and positioned as desired by the application. The control used for cell editing does not necessarily have to have the same dimensions as the cell being edited. It can also be larger or smaller. Once the EditSetup event ends, cell editing has started.

While a cell is being edited, the events of the control used for cell editing can be used to interpret and intercept keystrokes (KeyDown event, KeyPress event, etc.). The control's KeyDown event and PreviewKeyDown event can be used to implement cell navigation, allowing the Tab key to advance to the next editable cell. The SftTree.EditNavigate method is useful in determining the next editable cell and it transfers cell editing to another cell.

Once cell editing is in progress, the user can end cell editing by hitting the Escape key (depending on the PreviewKeyDown event implementation) or by clicking outside the cell being edited. Whenever cell editing ends, data entered must be validated (unless the user is abandoning the input data, for example by hitting the Escape key). The EditValidate event occurs when the new contents of the cell being edited are to be validated. An application can test the new input data, display an error message if necessary and cell editing can resume.

The EditEnded event occurs after input validation has occurred (EditValidate event) and the input data is valid. This event is used to save input data in the tree control and to hide and disable the control used for cell editing.