Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Custom Paint Card Field Values Depending on Field Positions

The following example handles the CardView.CustomDrawCardFieldValue event to custom paint card field values in the Price column.

CustomDrawCardFieldValue_2

private void cardView1_CustomDrawCardFieldValue(object sender, Views.Base.RowCellCustomDrawEventArgs e) {
    if (e.Column.FieldName != "Price") return;
    // The brush to fill the cell background.
    Color color1 = Color.FromArgb(40, 170, 225);
    Color color2 = Color.FromArgb(35, 80, 160);
    Brush brush = e.Cache.GetGradientBrush(e.Bounds, color1, color2, LinearGradientMode.Horizontal);
    e.Appearance.ForeColor = Color.White;
    e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold);
    e.Cache.FillRectangle(brush, e.Bounds);
    e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds);
    // Prevent default painting.
    e.Handled = true;
}