DevExpress GridControl Displays Class Name Instead of Empty String

795 views Asked by At

I have an application within which I am using a DevExpress GridControl. A column is populated correctly EXCEPT when the property returns a string.Empty value. In this case, the object name of the form X.Y.Z is displayed.

If I return a " " string an empty string value is displayed as I would like. If I over ride the ToString method on the class and return a string.Empty value, then an empty string is displayed in the field.

Why doesn't returning string.Empty display the expected value when I return it from the property? And, is there a way to specify that I want string.Empty as the default value for the column other than over riding ToString?

2

There are 2 answers

0
potehin143 On

Please check that your property value is string (not the instance of class) As default auto populated columns would be done for any property.

to cancel autogeneration of column use attribute [Display(AutoGenerateField = false)]

(instance of class).ToString() will return the name of class to;

0
Dmitry Gribkov On

1) You can use event CustomColumnDisplayText

private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
   if(e.Column.FieldName=="mycolumn")
   {
      e.DisplayText = (e.Value as MyClass).Product.Name;
   }
}

2) You can use column.UnboundExpression to display any structure

GridColumn column = gridView1.Columns.AddVisible("Product.Brand", string.Empty);
column.UnboundExpression = "[Product].Brand.Name";
column.UnboundType = DevExpress.Data.UnboundColumnType.Object;
gridView1.Columns.Add(column);