Connecting Tech Pros Worldwide Forums | Help | Site Map

[VB .NET] DataGridView with different combobox members

Newbie
 
Join Date: Jul 2007
Posts: 8
#1: Jul 22 '07
Hi,
I have a datagridview which has 3 columns.
Product : textBox
Suplier : comboBox
Price : textBox

Everytime I add a product to Product column, I want to have the list of supliers that can supply the product in the combobox.

At this moment I can do this in Visual Basic 2005, but the comboBox list all the supliers instead of only the supliers that can supply a certain product.

Could someone give me an example how to do this?

regards
AL



dip_developer's Avatar
Expert
 
Join Date: Aug 2006
Location: Asansol
Posts: 641
#2: Jul 23 '07

re: [VB .NET] DataGridView with different combobox members


Quote:

Originally Posted by akal483

Hi,
I have a datagridview which has 3 columns.
Product : textBox
Suplier : comboBox
Price : textBox

Everytime I add a product to Product column, I want to have the list of supliers that can supply the product in the combobox.

At this moment I can do this in Visual Basic 2005, but the comboBox list all the supliers instead of only the supliers that can supply a certain product.

Could someone give me an example how to do this?

regards
AL

how are you populating the combobox???What is the select query if any you are using????
Newbie
 
Join Date: Jul 2007
Posts: 8
#3: Jul 23 '07

re: [VB .NET] DataGridView with different combobox members


Thank you for your reply.
I am using unbound datagridviewcomboboxcolumn for suplier column.
But since it is datagridviewcomboboxcolumn, I only can assign once for all rows. (Store Procedure from SQL Server as source for this combo)

I don't have any idea, how to solve this problem.

regards,
AL
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#4: Jul 23 '07

re: [VB .NET] DataGridView with different combobox members


I believe that you need to change the stored procedure. Here is an article that may help:
Running Stored Procedures with ASP.NET
Newbie
 
Join Date: Jul 2007
Posts: 8
#5: Jul 23 '07

re: [VB .NET] DataGridView with different combobox members


Hi Kenobewan, thank you for your guidance.
At this moment my problem is how to make suplier combobox has different list in every row. I want suplier lists that related with a certain product instead of providing all the supliers.
Let say "product A" only has "Suplier B", "Suplier D" and "Suplier E",
"Product B" only has "Suplier A", "Suplier C", and
"Product C" only has "Suplier B", "Suplier D".
I can provide store procedure for this, but I don't know how to put this different datas in datagridviewcomboboxcolumn.

regards
AL
Newbie
 
Join Date: Jul 2007
Posts: 11
#6: Jul 24 '07

re: [VB .NET] DataGridView with different combobox members


When user leaves Product cell, we will load all suppliers who supply that product and assign that collection to corresponding Combobox cell.
We will do all steps in CellLeave() method of DataGridView.

Hope help.
Newbie
 
Join Date: Jul 2007
Posts: 8
#7: Jul 24 '07

re: [VB .NET] DataGridView with different combobox members


Hi Jinnee,
I assume that you suggest me to use datagridcomboboxcell.
Is that right?
I would appreciate if you could give me an example how to add datagridcomboboxcell with different items to the datagridview.
Member
 
Join Date: Jul 2007
Location: Pretoria, South Africa
Posts: 83
#8: Jul 24 '07

re: [VB .NET] DataGridView with different combobox members


Howdy -

I kinda understand the problem - you want to change the data populated in a specific drop down cell of a datagridview?

It's actually fairly simple, if you use a bit of OO principles... Here's what you need to do: For every new row that is added (or wherever you want the supplier list to be populated), declare a new DataGridViewComboBoxCell, which you then populate with your list of suppliers as you would anormal combobox (using the .Items.Add() method). Then, once loaded, set the cell of the row you are working with equal to the new DataGridViewComboBoxCell...
Expand|Select|Wrap|Line Numbers
  1. myDataViewGrid.Rows[myDataViewGrid.Rows.Count - 1].Cells["colSuppliers"] = myNewDataGridViewComboBoxCell
  2.  
I don't know if you can easily cast objects in VB, but in C# the really easy way is to cast the existing cell while using it, as follows:
Expand|Select|Wrap|Line Numbers
  1. ((DataGridViewComboBoxCell)myDGV.Rows[myDGV.Rows.Count - 1].Cells["colSuppliers"]).Items.Clear;
  2. ((DataGridViewComboBoxCell)myDGV.Rows[myDGV.Rows.Count - 1].Cells["colSuppliers"]).Items.Add("Supplier A");
  3. ((DataGridViewComboBoxCell)myDGV.Rows[myDGV.Rows.Count - 1].Cells["colSuppliers"]).Items.Add("Supplier B");
  4.  
Hope it answers your question
Newbie
 
Join Date: Jul 2007
Posts: 8
#9: Jul 25 '07

re: [VB .NET] DataGridView with different combobox members


Thank a lot RoninZa.
your guidance has solve my problem.

Regards
AL
Reply