2013-02-16 320 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