1
如何將ObservableCollection<updateData>
updateCollection
綁定到DataGrid
?我嘗試了幾個解決方案,但似乎沒有工作,因爲行被添加到集合中,但沒有顯示在網格上。我試圖綁定到類只,然後我可以添加行,但當我嘗試編輯他們時,我得到錯誤'EditItem' is not allowed for this view
。網格是以下將ObservableCollection綁定到DataGrid
<DataGrid Name="dgv" Grid.ColumnSpan="7" AutoGenerateColumns="False" ItemsSource="{Binding updateCollection}" IsSynchronizedWithCurrentItem="True" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Hour" SelectedValueBinding="{Binding Active}" ItemsSource="{StaticResource hoursList}" DisplayMemberPath="Key" SelectedValuePath="Value"/>
<DataGridComboBoxColumn Header="Origin" SelectedValueBinding="{Binding Origin}" ItemsSource="{StaticResource originList}" DisplayMemberPath="Key" SelectedValuePath="Value"/>
<DataGridTextColumn Header="P" Binding="{Binding Path=Price}"/>
<DataGridTextColumn Header="Q" Binding="{Binding Path=Quantity}"/>
</DataGrid.Columns>
而且updateData
類如下:
public class updateData
{
public string Price { get; set; }
public string Quantity { get; set; }
public string Origin { get; set; }
public string Hour { get; set; }
}
DataContext DataGrid使用什麼? – ASh
你見過這個:http://stackoverflow.com/questions/18578254/datagrid-edition-edititem-is-not-allowed-for-this-view-when-bound-to-a-wpf-da? – Silvinus
@ASh我試着設置'dgv.DataContext = updateCollection',但它沒有改變任何東西。 – Hauba