Skip to main content

GridView.CalcPreviewText Event

Enables you to provide custom text for preview sections.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v24.2.dll

Declaration

[DXCategory("Data")]
public event CalcPreviewTextEventHandler CalcPreviewText

Event Data

The CalcPreviewText event's data class is CalcPreviewTextEventArgs. The following properties provide information specific to this event:

Property Description
DataSourceRowIndex Gets the index of the row in the underlying data source.
PreviewText Gets or sets a text to display within the preview section.
Row Gets the object that is the currently processed row.
RowHandle Gets the handle of the row whose preview text is to be generated.

Remarks

If the View’s GridOptionsView.ShowPreview option is enabled, each row displays a preview section. You can use the GridView.PreviewFieldName property to specify the field to provide the content displayed within such sections. If you need preview sections to display values from several fields or display custom text, handle the CalcPreviewText event.

The CalcPreviewText event is raised for each row requiring preview section text. The current row is identified by the CalcPreviewTextEventArgs.RowHandle parameter. The preview section’s text should be assigned to the GridView.PreviewFieldName property.

After a CalcPreviewText event handler has been executed, the View calculates the preview section’s height based on the preview text, the GridOptionsView.AutoCalcPreviewLineCount and the GridView.PreviewLineCount property values.

The GridView.CustomDrawRowPreview event allows you to provide more complex preview customization. It enables you to paint preview sections manually, specify custom styles for individual sections, etc.

Example

This example customizes the row preview text.

using DevExpress.XtraGrid.Views.Grid;

   private void gridView1_CalcPreviewText(object sender, CalcPreviewTextEventArgs e) {
    GridView view = sender as GridView;
    if (view == null) return;
    e.PreviewText = "Item: " + e.PreviewText + "; Units: " + 
        view.GetRowCellDisplayText(e.RowHandle, _
        view.Columns["UnitsOnOrder"]) + ".";
   }
See Also