473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Cor can u help again?

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
Jul 21 '05 #1
1 1424
Cor
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

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Phil Powell | last post by:
I am having this problem: My PHP script will set a cookie, it's there in my /Cookies folder. I delete the cookie (I have to for testing purposes, the PHP script I run behaves according to this...
5
by: Bruce | last post by:
I have a number of forms that do significant work based on variables POSTed from the form. What is the common method of detecting and preventing this work from being done when the form is POSTed as...
8
by: jon morgan | last post by:
OK, I'm going to be brave. There is a bug in VS.Net 1.1 that causes random compiler errors. I have raised this issue in posts at least three time in the past couple of months without attracting...
17
by: Gabriel Mejía | last post by:
Services or applications using ActiveX Data Objects (ADO) 2.0 or greater may intermittently return empty recordsets on queries that should be returning valid results. At the time the problem...
3
by: penny336 | last post by:
dear all, i am using vc++ 6.0 sp5 i have a class called Address,it allocated some memory space for streetname and city i first define it as Address add = new Address("Madrian","UK"); ......
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
6
by: teedilo | last post by:
We have an application with a SQL Server 2000 back end that is fairly database intensive -- lots of fairly frequent queries, inserts, updates -- the gamut. The application does not make use of...
34
by: Reinhold Birkenfeld | last post by:
Hi, the arguments in the previous thread were convincing enough, so I made the Path class inherit from str/unicode again. It still can be found in CVS:...
5
by: Mike TI | last post by:
March 24, 2006 Hi all I am new to VB.NET and am using VB.NET 2005. I have an MDI form with a Split Container Control. On demand I am adding and removing User Controls on Panel 2. I am using...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.