下面的示例代码接管了 CardView.CustomCardCaptionImage 事件,为了指明汽车所属的类别,在卡片标题中显示了自定义图像。 这些图像被存储在 ImageList 组件中,此组件被指派到视图的 ColumnView.Images 属性。

下面的插图展示了结果:

C#CopyCode image复制代码
using DevExpress.XtraGrid.Views.Card;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;

private void cardView1_CustomCardCaptionImage(object sender, CardCaptionImageEventArgs e) {
   string cellValue = cardView1.GetRowCellDisplayText(e.RowHandle, colCategory);
   if (cellValue == null) return;
   foreach(ImageComboBoxItem item in ((RepositoryItemImageComboBox)colCategory.ColumnEdit).Items) {
      if(cellValue == item.Description) {
         e.ImageIndex = item.ImageIndex;
         return;
      }
   }
}
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraGrid.Views.Card
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Repository

Private Sub CardView1_CustomCardCaptionImage(ByVal sender As Object, _
ByVal e As CardCaptionImageEventArgs) Handles CardView1.CustomCardCaptionImage
    Dim cellValue As String = CardView1.GetRowCellDisplayText(e.RowHandle, colCategory)
    If cellValue = Nothing Then Exit Sub
    Dim item As ImageComboBoxItem
    For Each item In CType(colCategory.ColumnEdit, RepositoryItemImageComboBox).Items
        If cellValue = item.Description Then
            e.ImageIndex = item.ImageIndex
            Exit Sub
        End If
    Next item
End Sub