hi every one. I need some ideas for the calculation. I have a form where admin can add the product. field names are Product_id,Name,Description,Quantity,Unit_price

now i have an other form which is used for buying products. What i want to do is when customer chooses the product, as soon as he/she enters the quantity it should automatically be multiplied by the unit price of that product e.g if unit price is 2pounds and quantity is 5 it should give me result straight away as 10. I am not sure which is suitable control for this .e.g Data gridview or some other controls. Really need help to get this done.

You can add this function in leave event of last text box.
.

txtmultipicaiton.text= val(productprize.text) * val(quntity.text)

yes you can do like what saleem says , but tell me how you are getting the rate of the product , ? then we are able to provide you useful code .

Regards

i am very confused here . Because i want to get the price of the particular item from the form name"Add product "where admin enters the inventory details. i want to get that price into the buying form and than multiply the price with quantity. Any idea how i would solve this issue.

You will need to reference the value in the textbox from Add Product.

Like:

BuyingForm.TotalTextBox.Text = Cdbl(AddProduct.PriceTextBox.Text) * Cint(BuyingForm.QuantityTextBox.Text)

But, you may have a problem.

Are you luaching the buying form FROM the add product form?

If not, you are not going to be able to get your value from that form.

You will have to get the value from a database or a text file.....

Are you using a database backend, or storing the values in project variables?

yes i am using sql server as my backend . And i have a table to add product and i have a table for "sale" the add table has fields like product_id,name,description,unit_price
and the sale product also has id like sale_id,Name,quantity and price. the price in the sale should be taken from add product table and should be multiplied in the sale table quantity.
could you please clarify it now.Thanks,

I would advice to use textBoxes, because you (or user) will work with one item (product) at a time.

Can I ask you where do you have stored the information about product, i mean how much is one unit?

Do you have a class like "ProductInfo", where you have properties: priductId, productName, pricePerUnit ?

If not, create one, and you will calculation will be based on these data.
Creare a generic list<T>, where T will be "ProductInfo".

Then bind this list to some control, like listBox, where all the products will be shown (so user can select one for buying).
And based on selection, you can simply calculate the total price, regarding how mnay units choosen.

So:
- listbox to have a list of all products
- a label to show total price
- a textbox to allow user to enter quantity (and dont forget to allow inserting numbers only).

Then pass this data back to main form, and show them in datagrdiview, or where ever.

txtmultipicaiton.text= val(productprize.text) * val(quntity.text)
use this fun in last event box hope you will solve the problem.

And as said, use an event to let only integers insertion (use keypress event).

Dear Dilse4SK,

As you mentioned that you have product information table where product ID, product name, unit price of that product etc. are there. And I am thinking that some records are already there.

  1. First of all, put a Combobox or listbox (for product name) and two label or textbox (one for unit price another for total price (after multiplication)).

  2. Load the product name into the combo box or list box from your product information table by using form load event.

  3. On selection of combobox or list box, product unit price should be displayed from your table in the textbox or label (write codes in the combox or list box select event or other)

  4. For multiplication unit price by order qty. and dispaying it in the textbox (already mentioned the textbox), write codes on the lost focus event of order quentity textbox (where user will put order qty.)

I have just given you the idea how to do that, you need to write the codes. Hope the idea will work for you.

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.