views:

55

answers:

1

I have a class:

class MyObject
{
  float f;
  int i;
}

When a collection of MyObject instances are bound to a grid on UI, we have a default display of the instances (one object for one row), which probably calls float.ToString() and int.ToString(). My question is that, how to customize this default behavior? How to add in some format control to the primitive types here when they are displayed?

Thanks.

+1  A: 

Every column has an option to use format. If you are using the designer then open the "Edit columns" and in a column property there is "DefaultCellStyle" and there you can set the format.

You can of course do the same in code.

PS> I assume you are using DataGridView not the old DataGrid.

kubal5003
Cool. Thanks. I guess what you mean 'do the same in code' is to set up column property in datagridview. Well, any possiblity to do it in MyObject class, like setting up an attribute?
Dodd
No you can't set it as attribute of your class. This is always a matter of setting up DGV. From code means: col.DefaultCellStyle.Format = "d";
kubal5003