Is there a way to complex databind to a column's header text? Or is the only way to manually set the values and listen for change events from the source?
For the record, I've tried both
MyDataGrid.DataBindings.Add("Columns[<columnIndex>].HeaderText",MySource,"MyProperty");
and
MyDataGrid.DataBindings.Add("Columns[\"ColumnName\"].HeaderText",MySource,"MyProperty");
to no avail, and neither DataGridViewColumn and DataGridViewColumnHeaderCell have a DataBindings property.
-
No, the column headers don't support data binding, since it is understood that this metadata will be (largely) static.
In this case, I would simply do it manually, as you propose (read from a property and subscribe to an event to update the column header).
For more complex requirements (for completeness only), you can take more control if you write your own
PropertyDescriptorimplementation, exposed by eitherTypeDescriptionProviderorITypedList- or even better, anIBindingListimplementation where you raiseListChangedevents of typeListChangedType.PropertyDescriptorChanged; however any of these is a significant amount of work, and it simply isn't worth it just for what you are suggesting.
0 comments:
Post a Comment