Items in listview control

  • Thread starter Thread starter OpticTygre
  • Start date Start date
O

OpticTygre

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
 
* "OpticTygre said:
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
///
 
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
 

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

Back
Top