0

In a loop which sets up my WPF DataGrid columns, I want to bind the column width to member 'i' in my 'WidthList' with the following code:

var bindingColumnWidth = new Binding(string.Format("WidthList[{0}]", i));
customBoundColumn.Width = bindingColumnWidth;

However, this gives me the error:

Cannot implicitly convert type 'System.Windows.Data.Binding' to 'System.Windows.Controls.DataGridLength'

How can I resolve this?

Caustix
  • 569
  • 8
  • 26
  • You might find this post helpful: [WPF DataGrid: DataGridComboxBox ItemsSource Binding to a Collection of Collections](http://stackoverflow.com/questions/1633800/wpf-datagrid-datagridcomboxbox-itemssource-binding-to-a-collection-of-collection) – Nano Taboada Oct 03 '11 at 05:21

1 Answers1

2

DataGridColumn has no SetBinding method, you should try this:

BindingOperations.SetBinding(customBoundColumn, DataGridColumn.WidthProperty, bindingColumnWidth);
Natxo
  • 2,917
  • 1
  • 24
  • 36
  • Thanks, this looks promising. I can't check it in my case though since it's still not working. I have started a new question [here](http://stackoverflow.com/questions/7639050/binding-the-visibility-property-of-a-wpf-datagrid-column-where-is-my-fault) and I will mark this as the answer if/when it all works. – Caustix Oct 03 '11 at 18:27