Easy way to display alias in Grid?
Hello,
let's say I have some int values, that are the internal representation of a more easy readable pendant:
1 = "Male"
2 = ""Female"
3 = "Not set yet"
My custom objects contain the int values (MyCustomObject.Gender).
Is it possible to implement a dynamic conversion, so the grid displays "Male" instead of 1?
Thanks a lot!
-
Hello,
The best way is to create your custom format:
class MyFormat : IFormat
{
public string Format(IDataField dataField)
{
int value = (int) dataField.Value;
switch(value)
{
case 1: return "Male";
case 2: return "Female";
case 3: return "Not set yet";
default: return "Undefined case";
}
}
public bool CanParse(string text, IDataField dataField)
{
return false;
}
public void Parse(string text, IDataField dataField)
{
//Implement this method if you want to use editors
}
}There are multiple ways to apply this format:
public class MyCustomObject
{
[Format(typeof(MyFormat))]
public int Gender { get; set; }
}
or
column.Format = new MyFormat();Best regards,
Dapfor
0
Please sign in to leave a comment.
Comments
1 comment