The DevExpress GridControl set a custom display control method
April 9, 2018 13:41:25 DS_ saplings read the number 634
For example, to display a string of sex, as the value stored in the database (1: Male 2: Female, 3: unknown).
method one:
Click "Run Designer" button on the control interface into the design.
Select the "Columns", add a hidden field, field values need to be bound to take the value displayed. The display gender, binding "Sex" field.
Add a display field, field shows expression.
Modify the properties UnboundExpression value: Iif ([SexExpression] <= 2 And [SexExpression]> 0, Iif ([SexExpression] == 1, 'M', 'F'), 'unknown').
Modify the properties of UnboundType value: String
Modify the properties FiledName values: SexDesc
Method Two:
Click "Run Designer" button on the control interface into the design.
Views GridView1 editing events CustomColumnDisplayText.
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { if (e.Column.FieldName == "Sex") { if (e.Value != null) { switch (e.Value.ToString().Trim()) { case "1": e.DisplayText = "男"; break; case "2": e.DisplayText = "女"; break; case "3": e.DisplayText = "未知"; break; default: e.DisplayText = ""; break; } } } }