listview issue

andreD

New member
Joined
Apr 7, 2009
Messages
4
Programming Experience
Beginner
OK this is probably really simple and i'm missing something easy! :D

heres the situation, i have a class called computersystem, in that class i have a method (function) that returns 3 values.

HERE IS the function for computer system class:

Public Structure Attributes
Public ip As String
Public networkName As String
Public dhcp As String
End Structure

Function ipAdd() As Attributes
Dim att As Attributes
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = true")

For Each ip As ManagementObject In searcher.Get()
Dim arrIPAddress As String()
Dim networkN As String
Dim dhcp As String

networkN = ip("Caption")
arrIPAddress = ip("IPAddress")
dhcp = ip("DHCPEnabled")

For Each arrValue As String In arrIPAddress
att.ip &= arrValue
Next
For Each arrValue As String In networkN
att.networkName &= arrValue
Next
For Each arrValue As String In dhcp
att.dhcp &= arrValue

Next
Next

Return att
End Function

NOW On a basic form1.vb
how do i add networkN , arrayIPAddress and dhcp in a list view box?
they show but in straight line not in rows. WHAT AM I DOING WRONG?
 
Last edited:
Umm I think you would do something like...

VB.NET:
Dim att as Attributes

att = ipAdd()

ListView1.items.add(att.ip)
ListView1.items.add(att.networkName)
ListView1.items.add(att.dhcp)

Although if you could provide the code that actually deals with putting those values into the ListView then we might be able to identify if you're doing something wrong.

Anyway I hope that helped, if it hasn't the please provide the code that you're currently using to populate the ListView.

Satal :D
 
almost there!!:D :D :D

ok, here is the code

code:
Dim ComputerSystem As New ComputerSystem
Dim netThings As ListViewItem


Private Sub btnIPConfig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIPConfig.Click
Dim att As ComputerSystem.Attributes
att = ComputerSystem.ipAdd()

netThings = lstIP.Items.Add(att.networkName)
netThings.SubItems.Add(att.ip)
netThings.SubItems.Add(att.dhcp)

'lstIP.Items.Add(att.networkName)

End Sub
still everything shows up as a long line,
i dont know if this helps but there are 2 nic cards that are being retrieved.
THANKs :D
 
Ow I think I understand what you mean now;

Ok I have attached a quick demo, unfortunately the PC that I'm currently using only has one NIC so I can't check that it works fully but it does get the one that I have.

Let me know if that helps

Satal :D
 

Attachments

  • WindowsApplication1.zip
    14.5 KB · Views: 33
Thank you!

IT WORKS, THANK YOU SOOOO MUCH
i see it working but i cannot understand it. can you please give me a brief detail how it works? i hope that's not a dumb question.
 
i hope that's not a dumb question.
My belief is that its only dumb not to ask a question if you don't understand.

Basically the problem was that you was only returning one Attributes structure from the function, but as you said you have two NICs you would need to return more than one Attributes structure.
So what I did was change the function so that you was returning a collection of Attributes (I choose the List collection simply because I like to specify exactly what will be stored in the collection, although could have quite easily used pretty much any collection).

The call to searcher.Get() will get one NIC at a time, so what I was did was get the information about that NIC into the variables and then create a new instance of the Attributes structure, which then I added to the collection 'rtn' (probably not the most appropriate name in the world but this was just a quick demo).
So once the loop had gone through the available NICs the function returned the collection of NICs which then I looped through in Form1_Load and added them to the ListView in the same way that you did.

Hopefully that has cleared up my code for you a little bit, if you need me to explain it more then feel free to let me know and I will do so.

Satal :D
 
Back
Top