I am attempting to bind a collection of nullable values (Items=new ObservableCollection<double?>{}
) to a datagrid. The below gives me the error
Value cannot be null. Parameter name: key
<DataGrid Name="pointList" ItemsSource="{Binding Path=Value.Items,Converter={l:SelectableListArrayToListConverter}}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Value" Binding="{Binding}"/>
</DataGrid.Columns>
</DataGrid>
when i try to use a converter i get the following error Two-way binding requires Path or XPath.
<DataGrid Name="pointList" ItemsSource="{Binding Path=Value.Items,Converter={l:SelectableListArrayToListConverter}}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Value" Binding="{Binding}"/>
</DataGrid.Columns>
</DataGrid>
public class SelectableListArrayToListConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is IEnumerable)
{
List<string> list = new List<string>();
foreach(var item in value as IEnumerable )
{
if (item == null)
list.Add("NON");
else
list.Add(item.ToString());
}
//Two-way binding requires Path or XPath
return list;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
I believe that the above error is because twoway binding isnt working with List list = new List();
I believe i am getting the error when itemssource builds the rows after Itemssource is set but before DataGridTextColumn Binding is set.
I have tried extensively to find a solution to this problem with not luck so far.
If there is any issue with this post please let me know and i will correct it.
Thanks.