dakota97 Posted November 14, 2003 Posted November 14, 2003 Hi all, I'm relatively new to VB.Net and I'm runing into a problem. I'm trying to create a cash register program that allows the user to type an item number into a textbox, click a button, and have the matching database record be populated in a listbox. Am I using the right control as far as using a listbox, or should I use something else? Afterwards I'll need to add more items to the listbox and calculate the total. Thanks in advance, Chris Quote if(computer.speed == "slow") { hamster.feed(); } if(computer.speed == "really slow") { hamster.kill(); BuyNewHamster(); }
Roey Posted November 14, 2003 Posted November 14, 2003 I am assuming that you want to put in an Item ID 1234 and return an item such as Dozen Eggs $4.50, then another item 1239 Bread $2.45 and then do a total. If that is the case I would probably use a Datagrid as it can have a column for description and price. Quote
dakota97 Posted November 19, 2003 Author Posted November 19, 2003 Thanks for the quick reply. Ok, I see understand what you mean as far as using the datagrid. My question is how can I add just one result to the grid? All of the post that I've come across describe how to populate a datagrid with all records in a table. I was however able to add a record to a listbox. What I came up with was using 3 listboxes to show the information. Is it possible to get a sum of the items in the PRICE listbox and display them in the SUBTOTAL textbox? Quote if(computer.speed == "slow") { hamster.feed(); } if(computer.speed == "really slow") { hamster.kill(); BuyNewHamster(); }
Machaira Posted November 19, 2003 Posted November 19, 2003 There's a couple of ways that I can think of to do this with just one ListBox: 1) Show the price in the item - "Milk ($1.49)" and parse the price when you want to do a total 2) Bind the ListBox to a dataset that contains 2 items - the name of the item, which is displayed, and the price, which isn't. Add items to the dataset as the item number is entered. Loop through the dataset and grab the price to total. 3) Keep a running subtotal as items are added if you're not concerned with the price of each item (probably not the best solution for a cash register) 4) Keep an array of prices for each item as they're added to the ListBox and loop through it to get the total. Doing #1 would be easy. Write a function that takes a string, parses out the price and returns it. Quote Here's what I'm up to.
Administrators PlausiblyDamp Posted November 19, 2003 Administrators Posted November 19, 2003 You could create a class that contains properties for the price and item name and override the ToString Method to generate the correct output. the following quick (and 100% non-tested code) should give you an idea. public class MyItem public ItemName as string 'Should really be a property public ItemPrice as decimal 'Should really be a property Public Overrides Sub ToString() as string return ItemName & " " & ItemPrice.ToString() End Sub End Class Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Machaira Posted November 19, 2003 Posted November 19, 2003 Overkill? Just my opinion. ;) :) Quote Here's what I'm up to.
Administrators PlausiblyDamp Posted November 20, 2003 Administrators Posted November 20, 2003 Seven lines of code is overkill? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.