Listbox

G

Guest

Hi

I wanted to know if this is possible
I have a listView (detail) that i am adding items to when a button is clicked
My listview has 2 columns. - Product and Quantity

The user selects the values from a combobox1 (product) and a textbox (quantity). They then hit the 'Add' button
Both these values are then added to a single row in my listview. The values are also added to an array that is in the background

If the user selects the product and quantity
Product Quantit
gloves
and then hits the add button this then goes into my listview and array
If they again select the same product.....
Gloves

a new row is created

i want the new quantity to be added to the previous inserted row instead of a new row being added. i.e i want the following displayed in my listview
Gloves 1

not
Gloves
Gloves

Is this possible
If it is can anyone help me out with this?
 
D

drayyarb

Jiten said:
*Hi,

I wanted to know if this is possible.
I have a listView (detail) that i am adding items to when a button i
clicked.
My listview has 2 columns. - Product and Quantity.

The user selects the values from a combobox1 (product) and a textbo
(quantity). They then hit the 'Add' button.
Both these values are then added to a single row in my listview. Th
values are also added to an array that is in the background.

If the user selects the product and quantity:
Product Quantity
gloves 2
and then hits the add button this then goes into my listview an
array.
If they again select the same product......
Gloves 8

a new row is created.

i want the new quantity to be added to the previous inserted ro
instead of a new row being added. i.e i want the following displaye
in my listview:
Gloves 10

not:
Gloves 2
Gloves 8

Is this possible?
If it is can anyone help me out with this? *

You need to loop through the listview for a match first, then if one i
found extract the quantity value into a variable. Add the ammount i
the textbox to the ammount in the variable. Delete the old entry fo
Gloves as an example and add the new entries back in.

A quick pseudo-code:

for loop to go through the contents of the list
if the combobox value equals the current listview item
add the current listview item's subitem(1) to the textbox value
delete the current listview item
add the combobox and total back into the listview
exit for
end if
nex
-
drayyar
 
G

Guest

Hi

Im confused on how to retrieve the current listview item. Do u know how i can get this value
I have included comments in the code below on parts i am stuck on. Any help would be great
This is what i done so far.

Dim ChosenProduct As Strin
ChosenProduct = CBoxProductName.Text.ToStrin
Dim Quantity As Intege
Quantity = txtQty.Tex

For i = 0 To LViewProductsReq.Items.Count -
if ........ 'how do i get the current item from my listview?? =
CBoxProductName.Text then
get the value of subitem containing the quantity and place into a variable
Dim VaribleQty as Integer = 'how do i get the current subitem row?
VaribleQty = VaribleQty + Quantit
'now add the new new quantity back to the listvie
Dim Item1 As New ListViewItem(ChosenProduct , 0

Item1.SubItems.Add(Quantity

'add the items to the listvie
LViewProductsReq.Items.Add(Item1
Next
 
C

Cor

Hi Jitten

I do not like this approach but it is the best I can find till now

See it just as some pseudo, because I type it here and probably not error
free

\\\
dim item as ListViewItem
For each item in myListview.Items
if item.Text = Mycombobox.text then
item.subitems(0).text = (Cint(item.subitems(0).text) +
Myvalue).tostring
exit for
end if
next
///

I hope this helps,.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top