Back to Devexpress

GridView.CalcPreviewText Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-f27438e4.md

latest5.3 KB
Original Source

GridView.CalcPreviewText Event

Enables you to provide custom text for preview sections.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Data")]
public event CalcPreviewTextEventHandler CalcPreviewText
vb
<DXCategory("Data")>
Public Event CalcPreviewText As CalcPreviewTextEventHandler

Event Data

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

PropertyDescription
DataSourceRowIndexGets the index of the row in the underlying data source.
PreviewTextGets or sets a text to display within the preview section.
RowGets the object that is the currently processed row.
RowHandleGets 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.

csharp
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"]) + ".";
   }
vb
Imports DevExpress.XtraGrid.Views.Grid

   Private Sub GridView1_CalcPreviewText(ByVal sender As System.Object, _
     ByVal e As CalcPreviewTextEventArgs) Handles GridView1.CalcPreviewText
      Dim view As GridView = sender
      If view Is Nothing Then
           Return
      End If
      e.PreviewText = "Item: " + e.PreviewText + "; Units: " + _
        view.GetRowCellDisplayText(e.RowHandle, _
        view.Columns("UnitsOnOrder")) + "."
   End Sub

See Also

Row Preview Sections

ShowPreview

PreviewFieldName

AutoCalcPreviewLineCount

PreviewLineCount

CustomDrawRowPreview

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace