I am retrieving the available wifi networks, and I want to display them in a sorted order in a TableLayoutPanel.
They should be sorted according to their "rssi": The smalller the "rssi" value, the closer they are to the user, and the more likely it's "theirs".
However, the wifi networks arrive asynchronously, and I need to re-sort them TableLayoutPanel each time a new one arrives.
For each wifi, I create a new TableLayoutPanel with various controls in it and place it in the main TableLayoutPanel like this:
Private _tlp As New List(Of TableLayoutPanel)
Private _iCount As Integer = 0
(...)
Dim enumResult = Await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector())
Try
adapter = Await WiFiAdapter.FromIdAsync(enumResult.ElementAt(0).Id)
Await adapter.ScanAsync()
Dim connected As Windows.Networking.Connectivity.ConnectionProfile = Await adapter.NetworkAdapter.GetConnectedProfileAsync()
Dim report = adapter.NetworkReport
For Each network In report.AvailableNetworks
Dim networkView As TableLayoutPanel = New TableLayoutPanel
'Add all controls to it
(...)
_tlp.Add(networkView) 'add it to my private List(Of TableLayoutPanel) so that I can keep an overview
tlpNetworksList.Controls.Add(networkView, 0, _iCount) 'Now add the small TableLayoutPanel to the big TableLayoutPanel at the next row
_iCount += 1
Next
And then I re-order them manually like this:
Me.tlpNetworksList.SetRow(_tlp(0), 2)
Me.tlpNetworksList.SetRow(_tlp(2), 0)
Here is a screenshot so that I people see that it's worth the hassles:
I am looking for a way to automatically sort the TableLayoutPanels.
I have read the following here:
// When adding and removing controls, the order is not kept.
var runsOrderedByStartDate = this.nodesFlowLayoutPanel.Controls.Cast<RunNodeControl>().Select(_ => new { StartDate = _.StartDateTime, RunControl = _ }).OrderBy(_ => _.StartDate).ToList();
// Sets index of controls according to their index in the ordered collection
foreach (var anonKeyValue in runsOrderedByStartDate)
{
this.nodesFlowLayoutPanel.Controls.SetChildIndex(anonKeyValue.RunControl, runsOrderedByStartDate.IndexOf(anonKeyValue));
}
Can somebody show me how to do this with my TableLayoutPanel?
I do not understand this code, to be honest, and I don't know where I could / would insert this.
Thank you!