I have the following code which is used to get various details about wireless networks;

// Lists all networks ssid, signal stregth, availability, & security
                Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                    listBox1.Items.Add(GetStringForSSID(network.dot11Ssid));
                foreach (Wlan.WlanAvailableNetwork network in networks)
                    listBox2.Items.Add(network.wlanSignalQuality + "%");
                foreach (Wlan.WlanAvailableNetwork network in networks)
                    listBox3.Items.Add(network.wlanNotConnectableReason);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                    listBox4.Items.Add(network.securityEnabled);

Currently, each detail is stored in a different listbox.

I have changed the code to the following;

// Lists all networks ssid, signal stregth, availability, & security
                Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                    listView1.Items.Add(GetStringForSSID(network.dot11Ssid));
                foreach (Wlan.WlanAvailableNetwork network in networks)
                    listView1.Items.Add(network.wlanSignalQuality + "%");
                foreach (Wlan.WlanAvailableNetwork network in networks)
                    listView1.Items.Add(network.wlanNotConnectableReason);
                foreach (Wlan.WlanAvailableNetwork network in networks)
                    listView1.Items.Add(network.securityEnabled);

All that happens is that all the data is written to the first column in a long list.

I know the code above (listVIew1.Items.Add) is wrong but can someone explain to me what the code is to get each foreach loop to place it's data in a new column.

Thanks in advance

What you need to do is have a single loop, then inside the loop create a new ListViewItem which will hold the main item in your array, then inside each iteration add a SubItem to your ListViewItem.

Here's an example

Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
foreach (Wlan.WlanAvailableNetwork network in networks)
{
	ListViewItem lv = new ListViewItem(network.dot11Ssid);
	lv.SubItems.Add(network.wlanSignalQuality + "%");
	lv.SubItems.Add(network.wlanNotConnectableReason);
	lv.SubItems.Add(network.securityEnabled);
	listView1.Items.Add(lv);                                   
}

thanks, that worked a treat!

No problem, glad I could help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.