(dataGrid2.Columns[0].GetCellContent(dataGrid2.Items[6]) as TextBlock).Text我用这种方式可以给TextColumn类型的列赋值(dataGrid2.Columns[0].GetCellContent(dataGrid2.Items[6]) as ComboBox).Text
可以给ComboBoxColumn类型的列赋值难道我wpf的datagrid取单元格的值一定要这么累?

解决方案 »

  1.   

    用WPF在非必要的情况下去跟UI打交道你就已经输了.
    绑定啊,操作数据.
      

  2.   


    datagrid我绑定了dataview数据源。
    当我修改了单元格数据,然后执行CellEditEnding的时候,发现datagird控件上修改的值没有同步变更到dataview,主要是这个问题,我没办法在数据源操作更改了的数据
      

  3.   

    呵呵,我是WPF菜鸟,多指点一下。
    怎么设置依赖属性,请教一下
      

  4.   

    先让要绑定的类继承DependencyObject
    再将要在界面上同步的属性注册成依赖属性 public string MyProperty
            {
                get { return (string)GetValue(MyPropertyProperty); }
                set { SetValue(MyPropertyProperty, value); }
            }        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty MyPropertyProperty =
                DependencyProperty.Register("MyProperty", typeof(string), typeof(ownerclass));
    用法同普通属性一样
      

  5.   

    LZ没理解前面几位的意思,他们所说的绑定,不光是将数据源绑定到Datagrid,包括Datagrid的列与实体的属性也需要绑定,如果你只是希望更新数据源,那么仅仅这样做就足够了;如果还需要在修改数据源时通知UI修改,那么数据源集合的实体还需要实现InotifyPropertyChanged接口,并在修改实体时触发属性通知事件