473,404 Members | 2,187 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,404 software developers and data experts.

Items in listview control

Hi folks,

I am unfamiliar with the listview control, and I need a bit of help. My
listview control has 2 columns. I'm trying to populate the first column
with text in a textbox when a user clicks the "add" button, and also
populate the second column with text depending on what went in the first
column. I have a few questions, though. I can add the first column text
simply with listview.items.add, but how do I add text to the second column?
Also, how would I cycle through the items in the listview control (first
column) to make sure I don't add duplicate entries? Thanks for any help.

-J
Nov 20 '05 #1
2 4223
* "OpticTygre" <op********@adelphia.net> scripsit:
I am unfamiliar with the listview control, and I need a bit of help. My
listview control has 2 columns. I'm trying to populate the first column
with text in a textbox when a user clicks the "add" button, and also
populate the second column with text depending on what went in the first
column. I have a few questions, though. I can add the first column text
simply with listview.items.add, but how do I add text to the second column?
\\\
Me.ListView1.Items(10).SubItems.Add("Foo")
///
Also, how would I cycle through the items in the listview control (first
column) to make sure I don't add duplicate entries? Thanks for any help.


\\\
Dim lvi As ListViewItem
For Each lvi In Me.ListView1.Items
...
Next lvi
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Something like this?

Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Dim sIP As IPAddress

If txtIPAddress.Text = "" Then Exit Sub

Try
sIP = IPAddress.Parse(txtIPAddress.Text)
Try
For Each lstviewitem As ListViewItem In lstIPAddresses.Items
If lstviewitem.Text = txtIPAddress.Text Then
MessageBox.Show("IP Address is already in list.",
"Invalid Entry", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
Next
Dim item1 As New ListViewItem(txtIPAddress.Text)
item1.SubItems.Add("Not yet tested")
lstIPAddresses.Items.Add(item1)
txtIPAddress.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Catch ex As Exception
MessageBox.Show("Not a valid IP Address.", "Invalid Entry",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtIPAddress.Clear()
End Try
End Sub
It works, but I don't know if it's the best way of doing it....

-J

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2m************@uni-berlin.de...
* "OpticTygre" <op********@adelphia.net> scripsit:
I am unfamiliar with the listview control, and I need a bit of help. My
listview control has 2 columns. I'm trying to populate the first column
with text in a textbox when a user clicks the "add" button, and also
populate the second column with text depending on what went in the first
column. I have a few questions, though. I can add the first column text simply with listview.items.add, but how do I add text to the second
column?
\\\
Me.ListView1.Items(10).SubItems.Add("Foo")
///
Also, how would I cycle through the items in the listview control (first
column) to make sure I don't add duplicate entries? Thanks for any
help.
\\\
Dim lvi As ListViewItem
For Each lvi In Me.ListView1.Items
...
Next lvi
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #3

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

Similar topics

2
by: TF | last post by:
Hi, Is there any way to change the text color of SOME of the ListBox(Windows Forms Control) items in VB.NET? TF
0
by: keith | last post by:
I have a form and added a RichTextBox and set Dock to TOP, added a Splitter and set Dock to TOP, and finally added a listView set Dock Fill. Then added several items to the listView control. ...
2
by: John R. | last post by:
I want to have a listbox that shows a checkbox and a textbox. I created a user control that has a checkbox and a textbox in it and have been trying to add it to a listbox but I can't get it to...
3
by: Holmes | last post by:
Hello Ran into a bit of a problem here and have now exhausted my resources to getting this working What I am trying to do is load and show a simple vb form with a listbox in it Dim...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
1
by: karachiite1 | last post by:
How can I remove an Item and all its subitems on double_click in a ListViewControl such a way that I will add the same removed items to three text boxes in a text boxes on the same form. My listview...
1
by: Diego F. | last post by:
Hi. I'm having a problem with listview controls. I'm using a control that adds drag and drop functionality to a listview (I get the control from codeproject). Now I'm having problems when...
3
by: RT | last post by:
Is there any way to make Listview items invisible or otherwise keep them from displaying? Seems like temporarily removing, then restoring later would be a severe runtime hit.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.