| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 970 人关注过本帖
标题:关于一段程序的理解 关于combobox
取消只看楼主 加入收藏
上帝之允
Rank: 1
等 级:新手上路
帖 子:67
专家分:5
注 册:2010-10-11
结帖率:73.68%
收藏
已结贴  问题点数:20 回复次数:3 
关于一段程序的理解 关于combobox
namespace TwoComboBoxs
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        NorthwindDataSet.ProductsDataTable productTable = new NorthwindDataSet.ProductsDataTable();
        NorthwindDataSet.CategoriesDataTable categoryTable = new NorthwindDataSet.CategoriesDataTable();
        
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            DataRowView rowView = comboBox1.SelectedItem as DataRowView;
         
           

             NorthwindDataSet.CategoriesRow row = rowView.Row as NorthwindDataSet.CategoriesRow;
         
            int id = row.CategoryID;
            productTable.DefaultView.RowFilter = string.Format("CategoryID = {0}", id);
            
        }
      

        private void Form1_Load(object sender, EventArgs e)
        {
            
            NorthwindDataSetTableAdapters.CategoriesTableAdapter categoryAdapter = new TwoComboBoxs.NorthwindDataSetTableAdapters.CategoriesTableAdapter();
            categoryAdapter.Fill(categoryTable);
             = categoryTable.DefaultView;
            comboBox1.DisplayMember = categoryTable.CategoryNameColumn.ColumnName;
            

            NorthwindDataSetTableAdapters.ProductsTableAdapter productAdapter = new NorthwindDataSetTableAdapters.ProductsTableAdapter();
            productAdapter.Fill(productTable);
             = productTable.DefaultView;
            comboBox2.DisplayMember = productTable.ProductNameColumn.ColumnName;
           
           


        }

    }
}
这里面用的是northwind,看不太懂,有没有sql server 相关的语句可以替换一下的
搜索更多相关主题的帖子: combobox 
2010-11-24 16:56
上帝之允
Rank: 1
等 级:新手上路
帖 子:67
专家分:5
注 册:2010-10-11
收藏
得分:0 
千万别沉呀!!! 有没有神呀!!!
2010-11-24 19:40
上帝之允
Rank: 1
等 级:新手上路
帖 子:67
专家分:5
注 册:2010-10-11
收藏
得分:0 
那换个问题吧
  DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select G_number from 商品表", conn);
            da.Fill(ds, "G_number");
            DataTable dt = ds.Tables[0];
            comboBox2.DataSource = dt;
            comboBox2.DisplayMember = "G_number";
            comboBox2.SelectedIndex = -1;    是form_load 中对combobox2的出定义,连接商品表中的G_number

  DataSet ds1 = new DataSet();
            SqlDataAdapter da1 = new SqlDataAdapter("select G_name from 商品表", conn);
            DataTable dt1 = ds.Tables[0];
            comboBox3.DataSource = dt1;
            comboBox3.DisplayMember = "G_name";
            comboBox3.ValueMember = "G_name";
            comboBox3.SelectedIndex = -1;  是form_load 中对combobox3的出定义,连接商品表中的G_name
 想选定combobox2中的下拉项时,combobox3中的值跟着改变


 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strSQL1 = "Select G_name from 商品表 where G_number=";
            strSQL1 += comboBox2.Text;
            DataSet ds1 = new DataSet();
            SqlDataAdapter da1 = new SqlDataAdapter(strSQL1, conn);
            da1.Fill(ds1, "商品表");
            DataTable dt1 = ds1.Tables["商品表"];
            comboBox3.DataSource = dt1;
            comboBox3.DisplayMember = "G_name";
            comboBox3.SelectedIndex = -1;

            

        }

现在提示错误无法绑定由多个部分组成的标识符 "System.Data.DataRowView"。
为什么



2010-11-24 22:52
上帝之允
Rank: 1
等 级:新手上路
帖 子:67
专家分:5
注 册:2010-10-11
收藏
得分:0 
回复 5楼 c1_wangyf
那句没有问题可以通过
2010-11-25 16:26
快速回复:关于一段程序的理解 关于combobox
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022299 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved