i have datagrid in my project which i bind my attributes collection like this:
<DataGrid
Grid.Row="1"
ItemsSource="{Binding Attributes}"
AutoGenerateColumns="False"
Margin="5"
>
<DataGrid.Columns>
<DataGridTextColumn Width="3*" Header="Name" IsReadOnly="True" Binding="{Binding name}" />
<DataGridTextColumn Width="3*" Header="Field" Binding="{Binding field}" />
<DataGridTextColumn Width="3*" Header="Type" Binding="{Binding type}" />
<DataGridTextColumn Width="3*" Header="Value" Binding="{Binding value}" />
the problem is that name, field and type are string and value is a list. how can i bind it to the Datagrid in this way:
Name Field Type Value
----- ------- ------ -----
name1 xField1 xType1 1
name1 xField1 xType1 2
name1 xField1 xType1 3
name1 xField1 xType1 4
name1 xField2 xType2 5
name2 xField2 xType2 20
name2 xField2 xType2 30
name2 xField2 xType2 40
name3 xField3 xType3 100
ItemsSource=”{Binding Attributes}” in my case Attributes is a list of 3 values (name1, name2, name3).
Assuming like you said value is a List(). If so, you possibly try to make a DataGridTemplateColumn instead of a DataGridTextColumn and make a datatemplate that holds a list or listview then each row will have a listbox/listview that show all the values that apply to that row. If you just want to show the count of value then you leave everything the way it is and just bind Value.Count . Hope this helps a little 🙂