今天问了几个问题了,今天最后一个我想实现一个dt同时绑定gridview与textbox,是绑定,不是点一下gridview select 出内容的绑定。
WINFORM里有databinder的可以实现这个功能。但是WPF里没这东东。只有个Binding 。但是这个Binding 用的时候怎么用也不对啊。
dgProjectInfo.SetBinding(dgProjectInfo.ItemsSource , bindt);
要写成这样的。
dgProjectInfo.SetBinding(DependencyProperty dp,bindt);
但是这个DependencyProperty 是什么东西,要怎么写?
SqlConnection scn = new SqlConnection();
        Access acc = new Access();        Binding bindt = new Binding();
        DataTable dt = new DataTable();private void BindingGr()
        {
            //原本思路:用BindDdata绑定GR与TEXT,WPF无法实现直接绑定
            //bindt.Source = dt;
            getLoadData("SELECT * FROM dbo.PM_ProjectInfo",ref dt);
            dgProjectInfo.Columns.Clear();
            dgProjectInfo.ItemsSource = dt.AsDataView();
            dgProjectInfo.Columns[0].Visibility = Visibility.Hidden;
            
            //dgProjectInfo.ItemsSource = bindt;
            //dgProjectInfo.SetBinding(dgProjectInfo.ItemsSource , bindt);
        }

解决方案 »

  1.   

    我只会在xaml里面写......悲剧了......
      

  2.   

    你想绑定DataTable中的一条记录到TextBox?
    还是绑定整个DataTable,需求不明.如果你要在后台代码写绑定,比如版本某个对象的一个string类型的属性到TextBox,可以这么写:        public class DataObject
            {
                public string StringProp { get; set; }
            }           DataObject obj= new DataObject();
                Binding bd = new Binding("StringProp");
                TextBox tb = new TextBox();
                tb.DataContext = obj;
                tb.SetBinding(TextBox.TextProperty, bd);
      

  3.   

    需要继承 INotifyPropertyChanged 的类来实现绑定。
      

  4.   

    既然是同时绑定GridView与TextBox当然是整个Table.