Combobox select - 2 items from single select
-
Wednesday, March 07, 2012 7:03 AM
I am a beginer in vb.net. For a school project, i have chosen inventory control as the subject. WIth help from videos, i have developed some basic forms with adding/updating.
The product table design is like this:
Name Type Size ProductGroupID Text 50 ProductName Text 100 ProductPurchasePrice Currency 8 ProductSellingPrice Currency 8 ProductExpiryMonths Long Integer 4 ProductUsage Memo - ProductsQty Long Integer 4 Now, i am designing the purchase/sales screens. I am showing the items name, qty, price in a datagrid. From the products table, I am able to select the 'ProductName' by giving it a combobox . I want the ProductSellingPrice also to appear in the next column of the grid. How can i achieve this?
Thanks for any help
All Replies
-
Wednesday, March 07, 2012 7:32 AM
I assume that you have done something and you don't want us to make your school project?
So show what you have done so far? Moreover because you use a datagrid, which is rare in the case the Microsoft one in a current (windows) forms project used.
More likely a datagridview or a 3th party datagrid is used.
Success
Cor- Edited by Cor LigthertMVP Wednesday, March 07, 2012 7:34 AM
-
Wednesday, March 07, 2012 8:19 AM
Perhaps I was not clear enough. I am using vs.net 2010 version and Access database. Some of the individual tables like suppliers,customers,products, etc are easy enough and made the forms. Basically its the visual studio generated forms. And watched the videos from MSDN to know how to create a search function, etc.
Small issue arose with master-child tables, but with simple operations, i am able to do it. But with this particular isse explained above, i am unable to proceed further and hence sought help. Here are some screen shots.
- Edited by sen kumar Wednesday, March 07, 2012 8:20 AM image
-
Wednesday, March 07, 2012 8:20 AMhere is another screen
-
Wednesday, March 07, 2012 8:48 AMWhat is the Procedure Of Filling Data grid view, if you use data set then add field is sql query it will automatically add column in DGV.
Art Of Living Is Art Of Giving
-
Wednesday, March 07, 2012 9:45 AM
Hello Sen,
Use this sample on our website.
http://www.vb-tips.com/StronglyTypedDataSet.aspx
If you have done that right click on the datagridview and set the correct controls for the columns (for instance comboboxcolumn), if you then still have problems with setting the members of the columns, than show us what you have coded so far.
Success
Cor- Edited by Cor LigthertMVP Wednesday, March 07, 2012 9:46 AM
-
Thursday, March 08, 2012 5:22 AM
Thanks for the responses.
I use a dataset to collect the records of 'ProductItems' from the Products table. In the Datagridview, I make the Item column, a combobox and bind the controls from the dataset to this column.
The problem is when i select a prodcut from the combobox, the next column of Price should automatically be filled. This where i face the problem. Because, the price should come as a sql source to the price column based on the Product choosen.
Here is the screen showing the selected prodcut:
-
Thursday, March 08, 2012 5:25 AM
From the above screen, look at the blue background cells.
1. Price - this one should come automatically when i choose an item from the ProductID column.
2. LineTotal - This is an unbound column in the grid. I am going to show the multiiplication of Price*PODetailDiscount*PODetailQty
thanks for any assiatance
-
Thursday, March 08, 2012 8:22 AM
After reading some articles, i am trying out a new approach. Instead of directly adding the items in the datagridview, first populate a set of text box controls and combobox. Here i am able to select the price based on the selected item of the combobox. See the screenshot:
But I am finding difficulty in making the values from textboxes to the datagridview. I tried the following code:
Private Sub btnGrdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrdAdd.Click Dim irow As Integer = dg1.Rows.Add For Each row In dg1.Rows row("ProductID") = 1 'cboProduct.Text row("ProductPrice") = 2 ' txtPrice.ToString row("PODetailQty") = 3 'txtQty.Text.ToString row("PODetailDiscount") = 4 'txtDis.Text.ToString row("LineTotal") = 5 'txtLinTotal.Text.ToString dg1.Rows.Add(irow) Next End Sub
but the error is ' Cant add to datagridview when the controls are bound to a dataset'
Kindly help
-
Thursday, March 08, 2012 12:42 PM
Then add the row to the DataSet, not to the DataGridView.but the error is ' Cant add to datagridview when the controls are bound to a dataset'
Armin
- Proposed As Answer by Cor LigthertMVP Thursday, March 08, 2012 1:07 PM
- Marked As Answer by Shanks ZenMicrosoft Contingent Staff, Moderator Thursday, March 15, 2012 3:38 AM
-
Thursday, March 08, 2012 3:00 PM
The issue here is the PODetailID and PurchaseOrderID are autogenerated by the database. Only with the datagridview, the relevent master/detail structure is maintained. With the code shown above, concurrency error is generated.
Is there any other way...like how to access the selecteditem index/text of the combobox from the datagridview. Based on this, i could theoratically generate an sql statement to choose the price and then send it to the grid?

