简体   繁体   中英

DevExpress GridControl Displays Class Name Instead of Empty String

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 XYZ 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?

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;

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM