473,670 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4240
* "OpticTygre " <op********@ade lphia.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.It ems(10).SubItem s.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.It ems
...
Next lvi
///

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

Private Sub btnAdd_Click(By Val sender As Object, ByVal e As
System.EventArg s) Handles btnAdd.Click
Dim sIP As IPAddress

If txtIPAddress.Te xt = "" Then Exit Sub

Try
sIP = IPAddress.Parse (txtIPAddress.T ext)
Try
For Each lstviewitem As ListViewItem In lstIPAddresses. Items
If lstviewitem.Tex t = txtIPAddress.Te xt Then
MessageBox.Show ("IP Address is already in list.",
"Invalid Entry", MessageBoxButto ns.OK, MessageBoxIcon. Information)
Exit Sub
End If
Next
Dim item1 As New ListViewItem(tx tIPAddress.Text )
item1.SubItems. Add("Not yet tested")
lstIPAddresses. Items.Add(item1 )
txtIPAddress.Cl ear()
Catch ex As Exception
MessageBox.Show (ex.Message)
End Try
Catch ex As Exception
MessageBox.Show ("Not a valid IP Address.", "Invalid Entry",
MessageBoxButto ns.OK, MessageBoxIcon. Warning)
txtIPAddress.Cl ear()
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********@ade lphia.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.It ems(10).SubItem s.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.It ems
...
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
12390
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
1030
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. When ran it, I cannot see the items in listView until dragged the Splitter control to very top. If I used a RichTextBox to replace the listView and typed some text in the box, I could see the text when ran it.
2
23353
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 show up for each item I add to the listbox. foreach (Column column in columns) { ColumnsListBox.Items.Add(column.Name); ColumnsListBox.Controls.Add(new ColumnListControl(true, column.Name,
3
2607
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 frm_nc_code As New frm_nc_sen frm_nc_code.Show( Well what I want to have happen is it loads the form then shows all of the controls on the form (especially the listview control which should be blank at this time)
5
10076
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 because the ListView seems to be trying to "re-select" items that are no longer there! for example, giventhat I have 3 items in my list: Select the first and remove it - no problem.
12
3401
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. Very simple. I would like to create listviewitem's for display in a listview control. The listview items need to contain properties from Internet Explorer windows i've managed to collect into an arraylist.
1
1851
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 looks like this: --------------------------------------------- Column1 | Column2| Column3 Item1 |Subitem1| Subitem3 ->double_click->send them to text boxes ---------------------------------------------
1
1604
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 dragging items that have images. I first thougth that an item has its image and I could drag the complete object, but I see that in the second listview the image doesn't appear. It appears again if I move it again to the first listview.
3
7642
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
8896
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8810
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.