PC Review


Reply
Thread Tools Rate Thread

Cor can u help again?

 
 
=?Utf-8?B?Sml0ZW4=?=
Guest
Posts: n/a
 
      25th Feb 2004
Hi Cor

I spoke with u previously about this problem i had and u gave me some code that helped me. That code worked fine but i have now encountered another issuee that im hoping u may know how to solve
What my code below is doin is if a combobox and textbox is not empty, it is adding the items to a listview
The listview has 2 columns...
Product Quantit

What i want to do is to add the product along with the quantity into the listview only if that product has not been inserted previously. If it has been inserted previosly then i do not want a new row to be added but i simply want the quantity to be incremented
e.g if Nintendo 3 already exists in the lisview, if the user again selects nintendo with a quantity of 2, i do not want this entire row to be added again. I only want Nintendo 5 to be displayed (only the quantity should be updated).
what currently happens is that if the same product is added again the listview is searched and the quantity is correctly updated. However the problem i have at the momnet is that a new row is also inserted after the quantity has been updated. Does anyone know how i can stop this? This is my full code..

If Not ((CBoxProduct.Text = "") Or (txtQty.Text = "")) The

Dim Product As Strin
Product = CBoxProduct.Text.ToStrin
Dim Quantity As Intege
Quantity = txtQty.Tex

Dim Item1 As New ListViewItem(Product , 0

Dim item As ListViewIte
For Each item In LViewProductReq.Item
If item.Text = Product The
'if product is already in the listview, update the quantity instaed of addin a new
' row into the listvie
item.SubItems(1).Text = (CInt(item.SubItems(1).Text) + Quantity).ToStrin
Exit Fo
End I
Nex

'if the product does not exist in the listview i want to add it to the listvie
Item1.SubItems.Add(Quantity

'add the items to the listvie
LViewMealBookings.Items.Add(Item1

Els
'else display a message to state all required field are neede
MsgBox("Please ensure all the required fields are entered correctly"
End If
 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      26th Feb 2004
Hi Jiten,

This is not difficult I think, there are more possibilities, I take the one
which needs the less changes and shows it the best to you.
>
>
> If Not ((CBoxProduct.Text = "") Or (txtQty.Text = "")) Then
>
> Dim Product As String
> Product = CBoxProduct.Text.ToString
> Dim Quantity As Integer
> Quantity = txtQty.Text
>
> Dim Item1 As New ListViewItem(Product , 0)

Dim found as boolean
Dim item As ListViewItem
> For Each item In LViewProductReq.Items
> If item.Text = Product Then
> 'if product is already in the listview, update the

quantity instaed of addin a new
> ' row into the listview
> item.SubItems(1).Text = (CInt(item.SubItems(1).Text) +

Quantity).ToString

found = true

> Exit For
> End If
> Next


if not found then

> 'if the product does not exist in the listview i want to add

it to the listview
> Item1.SubItems.Add(Quantity)
>
> 'add the items to the listview
> LViewMealBookings.Items.Add(Item1)


end if
> Else
> 'else display a message to state all required field are

needed
> MsgBox("Please ensure all the required fields are entered

correctly")
> End If



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:36 AM.