Master-Detail Tutorial. Step 5: Specifying Editors for Items
- 3 minutes to read
Assigning editors to items allows the end-user to edit dataset fields in a more convenient way. In this section, editors are assigned to three items:
a radio group (TcxRadioGroup) is assigned to the GENDER column in the tvPersons View
a lookup editor (TcxLookupComboBox) is assigned to the PERSONID column in the tvStaff View
an image editor (TcxImage) is assigned to the SCREEN row in the cvFilmScreens View
To assign editors to items in this tutorial, use the Properties property.
Note
to specify the editor via code, you should use the PropertiesClass property as well.
- Activate the Component Editor and click the tvPersons box on the Structure panel and this displays the View’s columns on the right. Select the tvPersonsGENDER item (the name for the GENDER column) in the list and switch to the Object Inspector and this should now display the properties of the item.
Set the column’s Properties property to RadioGroup by selecting the corresponding value from the dropdown list:
Now expand the Properties property and click the ellipsis button in the Items value box. This opens a standard collection editor where we can now add items:
Add two items by clicking the button twice. Items will be used to represent the male or female sex of a person. Set the Caption property of the first item to Male and the Value property to True.
For the second item, set the Caption property to Female and the Value property to False.
The following image shows a cell from the GENDER column with a radio group specified as an editor:
- The tvStaffPERSONID column contains numerical identifiers of persons from the PERSONS table. It corresponds to the ID column from this table, thus allowing you to specify the lookup combo box as an editor. Instead of the person identifier, the editor will display the person’s name in the edit box. The dropdown window of the lookup will display the first and the second name of the person.
Display the properties of the tvStaffPERSONID column of the tvStaff View in the Object Inspector as shown above. Set its Properties property to LookupComboBox. Then set the attributes of the Properties object as follows:
- ListSource to dsPersons
This sets the source of records displayed in the dropdown and in the edit box of the lookup combo box.
- ListFieldNames to the FIRSTNAME;SECONDNAME string
The ListFieldNames property identifies fields displayed in the dropdown of the lookup editor.
- KeyFieldNames to ID
The KeyFieldNames property specifies the field(s) used to identify records from ListSource. The values of this field must match the values of the current column (tvStaffPERSONID).
- DropDownWidth to 200
This sets the width of the dropdown window.
- ListFieldIndex to 1
The ListFieldIndex addresses the column in the dropdown to display in the edit box. The value of the property defines a zero-based index of a field within the ListFieldNames list. ListFieldIndex is set to 1 and so addresses the SECONDNAME field.
The following image shows a lookup editor assigned to the tvStaffPERSONID column:
- For the SCREEN item of the cvFilmScreens View, set its Properties property to Image. Then set the item’s properties to the following values:
- Properties.GraphicClassName to TJPEGImage
Graphics provided by the dataset field are interpreted as JPEG images.
- Properties.Stretch to True
This stretches the image to accommodate the size of cells.