刚从web 转过来。在绑定时不知道怎么梆  谢谢大家告诉下思路 或发一两个小例子。

解决方案 »

  1.   

    绑定就是填充,SDK中有说明.和WEB一个道理.
      

  2.   

    DataGridView绑定
    grdResult.DataSource = ds.Tables[0];
      

  3.   

    public void model()
    {

    string sql="SELECT DISTINCT 部門名, 帳票用CD "+
    "FROM            dbo.MST_tyouhyouCD "+
    "ORDER BY     帳票用CD"; SqlDataAdapter bumenadp=new SqlDataAdapter(bumens,conn);
    DataSet bumenset=new DataSet();

    bumenadp.Fill(bumenset); int i;
    for(i=0;i<bumenset.Tables[0].Rows.Count;i++)
    {
    listBox1.Items.Add(bumenset.Tables[0].Rows[i][0]);
    }
    }
      

  4.   

    可不可以帮忙写个绑 combobox 的例子啊。。谢了。
      

  5.   

    web里这三句
    DropDownList1.DataSource = ...;
    DropDownList1.DataTextField=...;
    DropDownList1.DataValueField=...;
    对应winform里就是
    comboBox1.DataSource=...;
    comboBox1.DisplayMember=...;
    comboBox1.ValueMember=...;
      

  6.   

    public void BindCombo()
    {
    string strSql="SELECT UserID,UserName FROM Users ORDER BY UserID";
    DataSet dataSet=New DataSet();
    SqlDataAdapter dataAdapter=new SqlDataAdapter(strSql,conn);
    dataAdapter.Fill(dataSet);//绑Combo
    this.ComboBox1.DisplayMember="UserName";
    this.ComboBox1.ValueMember="UserID";
    this.ComboBox1.DataSource=dataSet.Tables[0];
    }
      

  7.   

    绑定一样呀
    如果是datagrid的话,还可以少句 
       dataGrid1.DataBinding();
      

  8.   

    grdResult.DataSource = ds.Tables[0];
      

  9.   

    comBox1.datasource = ds.tables[0];
    comBox1.displaymember = 字段名
      

  10.   

    TO 冰灵儿。要不要  combobox1.DataBinds();
      

  11.   

    this.username.DisplayMember="wdmc";
    this.username.ValueMember="wdbh";
    this.username.DataSource=ds.Tables["df_wdjsb"];没用啊
      

  12.   

    ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemwindowsformslistcontrolclassdatasourcetopic.htm
      

  13.   

    public void model()
    {

    string sql="SELECT DISTINCT 部門名, 帳票用CD "+
    "FROM            dbo.MST_tyouhyouCD "+
    "ORDER BY     帳票用CD"; SqlDataAdapter adp=new SqlDataAdapter(sql,conn);
    DataSet bset=new DataSet();

    adp.Fill(bset); int i;
    for(i=0;i<bumenset.Tables[0].Rows.Count;i++)
    {
    ComboBox1.Items.Add(bumenset.Tables[0].Rows[i][0]);
    }
    }
    这样就可以了,能说说具体你要什么样的棒定吗?(实现功能)
      

  14.   

    这样绑着没有值 。我要有 value 和 text 的 combobox
      

  15.   

    this.username.DisplayMember="wdmc";
    this.username.ValueMember="wdbh";
    this.username.DataSource=ds.Tables["df_wdjsb"];这样写OK 没错误 也没反应
    this.username.DataSource=ds.Tables["df_wdjsb"];
    this.username.DisplayMember="wdmc";
    this.username.ValueMember="wdbh";
    这样写就出现错误了。说不能绑定到什么什么的
      

  16.   

    可以参考这里的例子,
    http://blog.csdn.net/zhzuo/archive/2004/08/06/67016.aspx
      

  17.   

    检查一下你的wdmc列是否都是为空的
      

  18.   

    VS2005开始推荐使用BindingSource
    BindingNavigator用起来也很方便。BindingSource bs = new BindingSource();
    bs.DataSource = ds.Tables["table"];dataGridView.DataSource = bs;
    bindingNavigator.BindingSource = bs;