Previously, I illustrated code samples taken from a
primitive base class I created for working with the essential functions with
data control fields. However useful that was, I figured that for a certain
percentage of situations I create data fields in, another level of abstraction
is handy. The following is a second base class that I created (called the
BaseSingleDataField), another level of abstraction is helpful to have. The
methods that are abstract in this base class are illustrated below; each one
has to perform a specific action. I will discuss each one in detail.
public abstract Control SetupEditControl();
This method creates an instance of the control that will
edit the value in insert or edit mode. This assumes that there is one instance
of a control that performs the editing. It is possible to work with more, but
the edited control has to be at the zero index mark.
public abstract string GetEditControlValue(TableCell cell);
The control representing the insert/edit interface has a
value, which will be used to update the dictionary with the new value from it.
However, the base class does not know how to get a value from the edit
interface control, so this method is in charge of handling, extracting that
value and providing it to the base class, which uses it to add the value to the
public abstract void BindEditControl(object control, bool insertMode);
The data, whatever that may be, needs bound to the control. An
insert mode flag determines whether the control is currently in insert mode;
the row state enumeration is not needed because this only works whenever in
edit mode, and read only mode is not an option. So, this method is in charge of
binding the edit control with the corresponding data field value. It is up to
the method to determine what field that is, and how to get the value.
protected abstract string GetDataItemFieldName(DataControlRowState state);
Although most data fields have a single DataField property,
I did not want that to be a limitation set in the primitive base class. So, as
an alternative, this class requires the overriding of a GetDataItemFieldName
method that returns the name of the field to bind with. The row state is also
passed because it is possible to have multiple field names, one for each state
(you never know how useful that could be).
Essentially, the basic actions are the editing interface
gets setup, gets bound, and returns its value. There is some additional
functionality for read-only mode illustrated later.