KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 I need to take first 5 letters from the CompanyName when databinding happens. I could hook on different DataGridView events (e.g. RowsAdded) and loop through all the rows and do the trick, but I'd like to find more sophisticated way to do this. Since I have decided to use databinding, looping through data and modifying it is a bit against the databinding concept. What I'm after, is how to do the same as below, but add custom formatting logic: dataGridView1.Columns[colSomeDate.Index].DataPropertyName = "SomeDate"; colSomeDate.DefaultCellStyle.Format = "yyyy"; I think I should implement IFormatProvider, but I don't quite understand how I should implement it. dataGridView1.Columns[companyName.Index].DataPropertyName = "CompanyName"; companyName.DefaultCellStyle.FormatProvider = new ShortText(); // ShortText should implement IFormatProvider
Tags (comma-separated)
Save Edits
Cancel