|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Custom Related Fields
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
There may be scenarios when you want to specify a relationship between two custom fields. For example, because SPFieldMultiColumn objects actually store their data as a single string, you cannot sort based on a single "column" in the object. In this scenario, you might want to associate another field with your multicolumn custom field, so that users could sort on the associated field instead. Windows SharePoint Services enables you to specify a related column for a custom field type.
This relationship, between a main field and a related field, enables you to specify in the column definition Collaborative Application Markup Language (CAML) when you want to render the related field in addition to, or even in place of, the main field. You could define your column rendering such that the related field always displays next to your custom multicolumn field.
To establish the relationship, set the RelatedField property of the main field to the internal name of the related field. For each main field, you can specify one related field.
The custom field developer must program the logic in the field editor control that stores the correct information in the main and related fields. Again using the preceding example, the developer would be responsible for implementing the field editor control so that it stored the information on which the user sorts in the related field, and the rest of the various "columns" in the multicolumn field itself.
After you establish the relationship between the main and related fields, you can specify in your main field definition when and how you want to render the related field. To display the related column, in the display pattern of your field set the UseRelatedField attribute of the Field or Column element to TRUE.
<RenderPattern Name="DisplayPattern"> <Switch> <!-- empty column check --> <Expr><Column UseRelatedField="TRUE"/></Expr> <!-- The true indicator for whether something is picked is the content of the ID field --> <Case Value=""> </Case> <Default> Test related field value: <Column UseRelatedField="TRUE" HTMLEncode="TRUE"/> </Default> </Switch> <!-- empty column check --> </RenderPattern> <!-- End of display pattern -->