使用Datagridview组合框 [英] working With Datagridview Combobox

查看:66
本文介绍了使用Datagridview组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我必须在winforms中动态显示DataGridView.在这里,第二列是我使用的组合框(列名称为产品代码").数据是从数据库中提取到组合框的,我的任务是,当我选择一个组合框项目时,我必须显示数据库中的下一个列.pls请参见代码段..

Actually that I Have to Display dynamically the DataGridView in winforms. Here 2nd column i had taken combobox(column name is "Product Code").And the data is taken from the database to the combobox, my task is that i have to display the next column from the data base when i selected a combobox item.pls see the code snippet..

private void Sale_Entry_Load(object sender, EventArgs e)
        {
            //DataGridView Source

            string selectQueryString = "SELECT * FROM Sales_Product_Details";

            da = new OleDbDataAdapter(selectQueryString, con);
            OleDbCommandBuilder oledbCommandBuilder = new OleDbCommandBuilder(da);

            DataTable dataTable = new DataTable("Entry_Data");
            da.Fill(dataTable);
            BindingSource bs = new BindingSource();
            bs.DataSource = dataTable;

            string product = "SELECT ID,ProductCode,ProductDescription FROM Products";

            OleDbDataAdapter oda = new OleDbDataAdapter(product, con);
            OleDbCommandBuilder ocbp = new OleDbCommandBuilder(oda);

            DataTable dtp = new DataTable();
            oda.Fill(dtp);
            BindingSource bsp = new BindingSource();
            bsp.DataSource = dtp;

            //sno
            DataGridViewTextBoxColumn ColumnSno = new DataGridViewTextBoxColumn();
            ColumnSno.HeaderText = "S No";
            ColumnSno.Width = 60;
            ColumnSno.DataPropertyName = "SNo";
            dataGridView1.Columns.Add(ColumnSno);

            //Product Code combo
            DataGridViewComboBoxColumn pc = new DataGridViewComboBoxColumn();
            pc.HeaderText = "Product Code";
            pc.Width = 100;
            pc.DataPropertyName = "ProductCode";

            pc.DataSource = bsp;
            pc.ValueMember = "ID";
            pc.DisplayMember = "ProductCode";
            dataGridView1.Columns.Add(pc);

            //Product Description
            DataGridViewTextBoxColumn pd = new DataGridViewTextBoxColumn();
            pd.HeaderText = "Product Description";
            pd.Width = 300;
            pd.DataPropertyName = "ProductDescription";

                   //HERE i have to write the code to display in the next column(i.e.,Product Description) -related data of the combobox selected item( from database)  when combobox item is selected.
            dataGridView1.Columns.Add(pd);
          

          
            //Quantity
            DataGridViewTextBoxColumn qty = new DataGridViewTextBoxColumn();
            qty.HeaderText = "Quantity";
            qty.Width = 80;
            qty.DataPropertyName = "Qty";
            dataGridView1.Columns.Add(qty);

            //Rate
            DataGridViewTextBoxColumn rate = new DataGridViewTextBoxColumn();
            rate.HeaderText = "Rate";
            rate.Width = 80;
            rate.DataPropertyName = "Rate";
            dataGridView1.Columns.Add(rate);

            //VAT
            DataGridViewTextBoxColumn vat = new DataGridViewTextBoxColumn();
            vat.HeaderText = "VAT";
            vat.Width = 80;
            vat.DataPropertyName = "VAT";
            dataGridView1.Columns.Add(vat);

            //Amount
            DataGridViewTextBoxColumn amount = new DataGridViewTextBoxColumn();
            amount.HeaderText = "Amount";
            amount.Width = 80;
            amount.DataPropertyName = "Amount";
            dataGridView1.Columns.Add(amount);


        }

推荐答案

您的组合框将具有与其相关的事件.您可以连接这些事件,并在其中进行任何操作.我认为这不是网站,因为您没有说过.

如果您需要更多具体的帮助,则需要发布代码.含糊的问题会得到含糊的答案.
Your combobox will have events tied to it. You can hook up those events, and do whatever you want inside them. I assume this is not a website, because you didn''t say it was.

You need to post your code if you want more specific help. A vague question gets a vague answer.


这篇关于使用Datagridview组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆