但是当我 将它 绑定到 DataGrid 时 没有任何数据显示出来啊。

解决方案 »

  1.   

    全部代码:using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace WindowsApplication1
    {
    /// <summary>
    /// Form2 的摘要说明。
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label lUserName;
    private System.Windows.Forms.Label lUserID;
    private System.Windows.Forms.Label lUserMail;
    private System.Windows.Forms.TextBox userName;
    private System.Windows.Forms.TextBox userID;
    private System.Windows.Forms.TextBox userMail;
    private System.Windows.Forms.Button goPrior;
    private System.Windows.Forms.Button goNext;
    private System.Windows.Forms.Button goFirst;
    private System.Windows.Forms.Button goLast;
    private WindowsApplication1.DataSet1 dataSet11;
    private BindingManagerBase myBind;
    private System.Windows.Forms.Label infor;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form2()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();
    myBind = this.BindingContext[dataSet11,"userTable"];
    //dataSet11.
    //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.lUserName = new System.Windows.Forms.Label();
    this.lUserID = new System.Windows.Forms.Label();
    this.lUserMail = new System.Windows.Forms.Label();
    this.userName = new System.Windows.Forms.TextBox();
    this.dataSet11 = new WindowsApplication1.DataSet1();
    this.userID = new System.Windows.Forms.TextBox();
    this.userMail = new System.Windows.Forms.TextBox();
    this.goPrior = new System.Windows.Forms.Button();
    this.goNext = new System.Windows.Forms.Button();
    this.goFirst = new System.Windows.Forms.Button();
    this.goLast = new System.Windows.Forms.Button();
    this.infor = new System.Windows.Forms.Label();
    ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
    this.SuspendLayout();
    // 
    // lUserName
    // 
    this.lUserName.Location = new System.Drawing.Point(16, 32);
    this.lUserName.Name = "lUserName";
    this.lUserName.Size = new System.Drawing.Size(56, 16);
    this.lUserName.TabIndex = 0;
    this.lUserName.Text = "userName";
    // 
    // lUserID
    // 
    this.lUserID.Location = new System.Drawing.Point(16, 64);
    this.lUserID.Name = "lUserID";
    this.lUserID.Size = new System.Drawing.Size(48, 16);
    this.lUserID.TabIndex = 1;
    this.lUserID.Text = "userID";
    // 
    // lUserMail
    // 
    this.lUserMail.Location = new System.Drawing.Point(16, 96);
    this.lUserMail.Name = "lUserMail";
    this.lUserMail.Size = new System.Drawing.Size(80, 16);
    this.lUserMail.TabIndex = 2;
    this.lUserMail.Text = "userMail";
    this.lUserMail.Click += new System.EventHandler(this.userMail_Click);
    // 
    // userName
    // 
    this.userName.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "userTable.userName"));
    this.userName.Location = new System.Drawing.Point(112, 32);
    this.userName.Name = "userName";
    this.userName.TabIndex = 3;
    this.userName.Text = "";
    // 
    // dataSet11
    // 
    this.dataSet11.DataSetName = "DataSet1";
    this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
    this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
    // 
    // userID
    // 
    this.userID.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "userTable.userId"));
    this.userID.Location = new System.Drawing.Point(112, 64);
    this.userID.Name = "userID";
    this.userID.TabIndex = 4;
    this.userID.Text = "";
    // 
    // userMail
    // 
    this.userMail.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "userTable.userMail"));
    this.userMail.Location = new System.Drawing.Point(112, 96);
    this.userMail.Name = "userMail";
    this.userMail.TabIndex = 5;
    this.userMail.Text = "";
    // 
    // goPrior
    // 
    this.goPrior.Location = new System.Drawing.Point(74, 136);
    this.goPrior.Name = "goPrior";
    this.goPrior.Size = new System.Drawing.Size(60, 23);
    this.goPrior.TabIndex = 6;
    this.goPrior.Text = "上一条";
    // 
    // goNext
    // 
    this.goNext.Location = new System.Drawing.Point(134, 136);
    this.goNext.Name = "goNext";
    this.goNext.Size = new System.Drawing.Size(60, 23);
    this.goNext.TabIndex = 7;
    this.goNext.Text = "下一条";
    this.goNext.Click += new System.EventHandler(this.goNext_Click);
    // 
    // goFirst
    // 
    this.goFirst.Location = new System.Drawing.Point(14, 136);
    this.goFirst.Name = "goFirst";
    this.goFirst.Size = new System.Drawing.Size(60, 23);
    this.goFirst.TabIndex = 8;
    this.goFirst.Text = "首记录";
    // 
    // goLast
    // 
    this.goLast.Location = new System.Drawing.Point(194, 136);
    this.goLast.Name = "goLast";
    this.goLast.Size = new System.Drawing.Size(60, 23);
    this.goLast.TabIndex = 9;
    this.goLast.Text = "尾记录";
    // 
    // infor
    // 
    this.infor.Location = new System.Drawing.Point(16, 8);
    this.infor.Name = "infor";
    this.infor.Size = new System.Drawing.Size(160, 16);
    this.infor.TabIndex = 10;
    this.infor.Text = "Loading...";
    // 
    // Form2
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(264, 173);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.infor,
      this.goLast,
      this.goFirst,
      this.goNext,
      this.goPrior,
      this.userMail,
      this.userID,
      this.userName,
      this.lUserMail,
      this.lUserID,
      this.lUserName});
    this.Name = "Form2";
    this.Text = "Form2";
    this.Load += new System.EventHandler(this.Form2_Load);
    ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
    this.ResumeLayout(false); }
    #endregion private void Form2_Load(object sender, System.EventArgs e)
    {

    myBind.Position = 0;
    infor.Text = "第一条记录";
    } private void userMail_Click(object sender, System.EventArgs e)
    {

    } private void goNext_Click(object sender, System.EventArgs e)
    {
    myBind.Position += 1;
    }
    }
    }