首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

“System.Windows.Controls.TextBox”不包含“DataBindings”的定义是咋回事

2013-08-01 
“System.Windows.Controls.TextBox”不包含“DataBindings”的定义是怎么回事?using Systemusing System.Col

“System.Windows.Controls.TextBox”不包含“DataBindings”的定义是怎么回事?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;


namespace SimpleBinding
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string connstring = @"
                server=.\sqlexpress;
                integrated security=true;
                database=northwind";
            string sql = @"
                select
                *
                from
                employees";
            SqlConnection conn = new SqlConnection(connstring);
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            da.Fill(ds, "employee");



            textBox1.DataBindings.Add("Text", ds, "employee.firstname");
            textBox2.DataBindings.Add("text", ds, "employee.lastname");

            
        }
    }
}


就最后两行DataBingings下面有两个红色下划线,然后说错误1“System.Windows.Controls.TextBox”不包含“DataBindings”的定义,并且找不到可接受类型为“System.Windows.Controls.TextBox”的第一个参数的扩展方法“DataBindings”(是否缺少 using 指令或程序集引用?)
但是我加了using System.Windows.Forms和dll引用的。不知道怎么回事。
[解决办法]
DataBindings属性在.net 1.0中就已经有了,但对于Client Profile,只在3.5 SP1以后提供,所以我想你应该是选错了.net框架的版本。
[解决办法]
还有一个办法可以试试,可以在设计器的里为控件指定绑定,看设计器会有什么反应。
[解决办法]
你的TextBox应该是WPF中的TextBox吧


            //WPF中的TextBox
            System.Windows.Controls.TextBox tbWpf = new System.Windows.Controls.TextBox();
            tbWpf.SetBinding(TextBox.TextProperty, "yourBind");
            
            //WinForm程序中的TextBox
            System.Windows.Forms.TextBox tbForm = new System.Windows.Forms.TextBox();
            tbForm.DataBindings.Add(new System.Windows.Forms.Binding());

热点排行