shsh_shah 0 Light Poster

Hi,
Hi,
I have a grid view and want to populate columns of gridview based on the selection from combobox. How to do that? Please help on this issue...

Problem: Below is my code which fills combobox and gridview columns...but it also display data as well in all columns as i do not want them to fill in automatically...

The columns I want to fill in after i select value from combobox are:
ProductName and Price..

Please help...

void fillData()
        {
            OleDbConnection database = new OleDbConnection(connectionString);
            database.Open();
            //OleDbDataAdapter adapter1 = new OleDbDataAdapter("select BillD.ProductName,BillD.ProductID,BillD.Saletype,BillD.InQty,BillD.SBtype,BillD.Dis1,BillD.Type,BillD.InPrice from BillDetails BillD", database);
            OleDbDataAdapter adapter1 = new OleDbDataAdapter("Select Products.ProdID,Products.ProductName,Packing.PackingName,Products.CPrice from Packing INNER JOIN Products ON Packing.PackingID=Products.Packing", database);

           
            DataGridViewComboBoxColumn dgridcolumn = new DataGridViewComboBoxColumn();
            dgridcolumn.Name = "Products";
            this.dataGridView1.Columns.Add(dgridcolumn);
           

            DataTable dt = new DataTable();
            DataTable packDT = new DataTable();
           
            adapter1.Fill(dt);
            dataGridView1.DataSource = dt;

            adapter1.Fill(packDT);
            dgridcolumn.DataSource = packDT;
           
            dgridcolumn.ValueMember = packDT.Columns[1].ColumnName.ToString();
            
            dgridcolumn.DisplayMember = packDT.Columns[1].ColumnName.ToString();
            
           
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.