本文主要是介绍【WinForm+DevExpress】CardView 设置字段的样式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
效果图
TotalAmount字段是新加的,用来计算总价(orderPrice*orderCount),在数据库表中不存在
实现
第一步:添加一个GridControl,设置在父容器中停靠,设置数据源,将GridControl的MainView转换成CardView
第二步:在Run DesDesigner设计界面中新加一列TotalAmount,设置列的Caption属性和FieldName属性为TotalAmount,
并且将字段的UnboundType设置成Decimal
第三步:给CardView添加CustomUnboundColumnData事件
private void cardView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e){if (e.Column.FieldName == "TotalAmount" && e.IsGetData){DataRow dataRow = jWDBDataSet4.Tables["tb_order"].Rows[e.ListSourceRowIndex];decimal orderPrice = dataRow["orderPrice"] == DBNull.Value ? 0 : Convert.ToDecimal(dataRow["orderPrice"]);int orderCount = dataRow["orderCount"] == DBNull.Value ? 0 : Convert.ToInt32(dataRow["orderCount"]);e.Value = orderPrice * orderCount;}}
第四步:给CardView添加CustomDrawCardFieldValue事件
private void cardView1_CustomDrawCardFieldValue(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e){Brush brush = e.Cache.GetGradientBrush(e.Bounds, Color.Aquamarine, Color.DarkSeaGreen, LinearGradientMode.Horizontal);if (e.Column.FieldName == "TotalAmount"){brush = e.Cache.GetGradientBrush(e.Bounds, Color.White, Color.SkyBlue, LinearGradientMode.Horizontal);e.Appearance.ForeColor = Color.Indigo;e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold);}e.Graphics.FillRectangle(brush, e.Bounds);e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds);e.Handled = true;}
这篇关于【WinForm+DevExpress】CardView 设置字段的样式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!