I\'m looking for a way to format DataGridViewTextBoxColumn so that the value to be databinded is formatted during databinding. For example I have a CompanyName property and
It sounds like IFormatProvider is exactly what you need. Then you can define different codes for the different formats you want for the different views.
From Codeproject.
public override string ToString()
{
return ToString("g", null); // Always support "g" as default format.
}
public string ToString(string format)
{
return ToString(format, null);
}
public string ToString(IFormatProvider formatProvider)
{
return ToString(null, formatProvider);
}
public string ToString(string format, IFormatProvider formatProvider)
{
if (format == null) format = "g"; // Set default format, which is always "g".
// Continue formatting by checking format specifiers and options.
}