Re: ValueListEditor

Posted by Guido, DelpiLand Team on February 25, 2005

In Reply to: Re: Creating objects on a form at runtime - how about a ValueListEditor? posted by Al on February 24, 2005

: I started having a look at the other components and found the ValueListEditor component which seems more appropriate. Do you have any pointers on how to use/reference it? All of my attempts have ended up with exception errors.

Difficult to say what could be wrong, I'd need more info... When do you get exceptions, and what does the error message say?
Anyhow, I set up a short list of important stuff that you can check.

After dropping a ValueList Editor on the form, in the Object Inspector set the following in "Options" properties to True:
- goEditing: allow the user to edit the contents of cells.
- goTabs: allow the user to navigate through the cells using the Tab and Shift+Tab keys.

Setting the properties below to True is up to you, depends from how you want the thing to work:

- doColumnTitles: the first row is a fixed (nonscrolling) row, that displays the captions specified in the TitleCaptions property.

- keyEdit: allow the user to edit values in the first (key-name) column. That is, the the user can specify the name in a name/value pair.
- keyAdd: allow the user to add new name/value pairs. The user can create new entries by pressing the Insert key or using the down arrow key when positioned on the last item.
keyAdd requires that keyEdit is also included.
- keyDelete: allow the user to delete name/value pairs by pressing the Delete key.
- keyUnique: the user can NOT create pairs with a name (key) that already exists in another pair. Attempting to add duplicate key causes an exception.
keyUnique requires that keyEdit is also included.

Attention! the property RowCount is a read-only property. This gives you the number of strings in the Strings property, plus the number of fixed rows (typically one, for the column titles).

A short general overview:

TValueListEditor is a specialized grid for editing string lists that contain name/value pairs in the form Name=Value. You can look up the value for any name using the Values property.

The grid contains two columns, one for the names ("keys") and one for the values. By default, the Name column is named "Key" and the Value column is named "Value". You can change these defaults by setting the TitleCaptions property.

You can control how users edit the entries in the Value column using the ItemProps property. Each item has a separate TItemProp object that lets you:

- Supply an edit mask to limit the valid input.
- Specify a maximum length for values.
- Mark the value as read-only.
- Specify that the value list editor displays a drop-down arrow that opens a pick list of values from which the user can choose or an ellipsis button that triggers an event you can use for displaying a dialog in which users enter values.

If you specify that there is a drop-down arrow, you must supply the list of values from which the user chooses. These can be a static list (the PickList property of the TItemProp object) or they can be dynamically added at runtime using the value list editorís OnGetPickList event. You can also combine these approaches and have a static list that the OnGetPickList event handler modifies.

If you specify that there is an ellipsis button, you must supply the response that occurs when the user clicks that button (including the setting of a value, if appropriate). You provide this response by writing an OnEditButtonClick event handler.

Accessing the string in a particular cell: use the Cells[aCol,aRow] property.
- ACol is the column coordinate of the cell. It can be 0 (for the name column) or 1 (for the value column).
- ARow is the row coordinate of the cell. It can range from 0 (for the title row) to the number of strings.

To access the strings in the name column, you can use the Keys property instead.
To access the strings in the value column, use can the Values property instead.
To access the underlying string list, use the Strings property.

You can save the strings to a file an later load them form a file like this:
// Later: ValueListEditor1.Strings.LoadFromFile('C:\test\mylist.txt');

In Delphi's Help, you can look up TValueListEditor.

Related Articles and Replies

[ Delphi Tutorials -- by DelphiLand ]