我是WPF的新手。我想從datagrid運行時刪除行。當我嘗試刪除像這樣的行時Wpf Datagrid刪除行問題
Datagrid.Items.Remove(eRow);
它給了我一個錯誤「錯誤是:在ItemsSource正在使用時操作無效,而是使用ItemsControl.ItemsSource來訪問和修改元素。
我在線閱讀,您可以使用ObservationCollection和InotifyPropertyChangedEvent但我不知道如何實現它。
我刪除這樣
按鈕,這是數據網格
<ctrls:RhinoDataGrid x:Name="dataGrid" Grid.Row="1" Margin="5" ItemsSource="{Binding Model.CurrentDataTable}"
Style="{StaticResource RhinoDataGridBaseStyle}" IsReadOnly="{Binding Model.IsLinkFile}"
SelectedValue="{Binding Model.CurrentDataRow}" SelectedValuePath="Row"
>
</ctrls:RhinoDataGrid>
請幫助我。謝謝。
ObservableCollection dtCollection = this.ItemsSource as ObservableCollection ; dtCollection.CollectionChanged + = new NotifyCollectionChangedEventHandler(dtCollection_CollectionChanged);像這樣的權利? –
好吧,沒有。您的基礎數據列表(原始文章中的Model.DataTable)應該是一個ObservableCollection,因此您可以將它用作XAML代碼中的綁定源。 DataGrid將自動附加到列表的CollectionChanged事件。請閱讀MSDN上的備註和示例。 [數據綁定部分](http://msdn.microsoft.com/en-us/library/ms752347.aspx)也應該對您有所幫助。 –
rumpelstiefel