2013-02-16 194 views
0

我遇到了WpfDataGrid問題。 我創建了一個控制,該控制打開一個窗口wpf datagrid不可編輯

var wb = new DataEntry(b, Connectionstring); 
wb.Show(); 

窗口DataEntry包含TextBoxDataGrid其示出了作爲不可編輯。

,我讀了建議插入一個帖子:我試過了,現在TextBox運作良好,但DataGrid仍然是不可編輯

ElementHost.EnableModelessKeyboardInterop(wb);wb.Show();

謝謝支持。

我補充一點,我使用

DataEntry class 

private ObservableCollection<RigaBarcode> _righeBarcode = new ObservableCollection<RigaBarcode>(); 


//so I create the customer object 

    private class RigaBarcode : INotifyPropertyChanged 
     { 
      public RigaBarcode(string barcode, string coordinate) 
      { 
       Barcode = barcode; 
       Coordinate = coordinate; 

      } 

      private string _barcode; 
      private string _coordinate;   

.... 白衣setter和getter代碼

public event PropertyChangedEventHandler PropertyChanged; 

      protected virtual void OnPropertyChanged(string propertyName) 
      { 
       PropertyChangedEventHandler handler = PropertyChanged; 
       if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); 
      } 

我添加和元素到此集合

_righeBarcode.Add(new RigaBarcode("1", "2"); 

在XAML我插入

DataGrid ItemsSource="{Binding .}" Name="Fustelle" Margin="10,23,10,10" Grid.Row="8" Grid.ColumnSpan="2" IsReadOnly="False" AutoGenerateColumns="False"> 
      DataGrid.Columns> 
        DataGridTextColumn Header="BarCode" Width="90" Binding="{Binding Barcode}"/> 
        DataGridTextColumn Header="Posizione" Width="90" Binding="{Binding Coordinate}"/> 
       /DataGrid.Columns> 
      /DataGrid> 

因此,我希望當Windows初始化數據網格具有1行可編輯的,但數據網格不存在此行,我不能添加其他行

+1

你的問題是什麼?你想讓'DataGrid'可編輯嗎?你有什麼嘗試?文檔是否支持編輯? – 2013-02-16 11:41:56

+0

開頭我編寫此代碼 WB =新的DataEntry(B,的connectionString); ElementHost.EnableModelessKeyboardInterop(WB); wb.Show(); 在一個窗口的形式和它的作品。但這只是一個考驗。 對於發行版,我需要將其插入到一個WPF窗口,當我做到這一點的數據網格變得不可編輯 – user2078205 2013-02-16 11:48:02

回答

0

MSDN

通過默認情況下,您可以直接在DataGrid中編輯項目。爲確保可以正確提交和取消編輯,DataGrid中的對象必須實現IEditableObject接口。或者,您可以將IsReadOnly屬性設置爲true以禁用DataGrid中的編輯。

您沒有說明您正在使用的框架的版本以及您的數據對象是否實現了IEditableObject接口。 據我所知,這隻支持.NET 4.0及以上版本。

+0

我使用.NET 4.0我嘗試實現IEditableObject但我沒有因此 – user2078205 2013-02-16 13:12:21

+0

你看了MSDN文章中,我掛?您是否嘗試訂閱不同的事件,例如* BeginEditCommand *?按F2有什麼作用? – Blachshma 2013-02-16 14:03:39

+0

我在我的問題 – user2078205 2013-02-16 15:16:24