ICustomFormatter, - DataGridView , .
column.DefaultCellStyle.FormatProvider . CellFormatting:
void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
if (e.CellStyle.FormatProvider is ICustomFormatter) {
e.Value = (e.CellStyle.FormatProvider.GetFormat(typeof(ICustomFormatter)) as ICustomFormatter).Format(e.CellStyle.Format, e.Value, e.CellStyle.FormatProvider);
e.FormattingApplied = true;
}
}
formatter :
public class MyEnumFormatter : IFormatProvider, ICustomFormatter {
public object GetFormat(Type formatType) {
if (formatType == typeof(ICustomFormatter))
return this;
else
return null;
}
public string Format(string format, object arg, IFormatProvider formatProvider) {
return ((NameOfEnumType)Convert.ToInt32(arg)).ToString();
}
}