private void UpdateClients() { clientList.Refresh(); foreach (var row in dataGridView1.Rows.Cast <DataGridViewRow>()) { // Mark as old data ((ClientTag)row.Tag).updated = false; } foreach (var client in clientList) { DataGridViewRow found = null; foreach (var row in dataGridView1.Rows.Cast <DataGridViewRow>()) { ClientTag tag1 = ((ClientTag)row.Tag); if (tag1.client.Equals(client)) { found = row; tag1.client = client; tag1.updated = true; } } if (found == null) { int index = dataGridView1.Rows.Add(); found = dataGridView1.Rows[index]; ClientTag tag2 = new ClientTag(); found.Tag = tag2; tag2.client = client; tag2.updated = true; } Color color = Color.Black; if (!client.Online) { color = Color.DarkGray; } found.Cells[0].Style.ForeColor = color; found.Cells[0].Style.SelectionForeColor = color; found.Cells[1].Style.ForeColor = color; found.Cells[1].Style.SelectionForeColor = color; found.Cells[2].Style.ForeColor = color; found.Cells[2].Style.SelectionForeColor = color; found.Cells[0].Value = client.DeviceName; found.Cells[1].Value = client.ClientAddr.ToString(); found.Cells[2].Value = client.Online ? (client.RefreshRates[0] + " FPS") : "Offline"; string buttonLabel = "Connect"; if (!client.Online) { buttonLabel = "Remove"; } else if (client.Version != HelloListener.ALVR_PROTOCOL_VERSION) { buttonLabel = "Wrong version"; } if ((string)found.Cells[3].Value != buttonLabel) { found.Cells[3].Value = buttonLabel; } } for (int j = dataGridView1.Rows.Count - 1; j >= 0; j--) { // Remove old row ClientTag tag3 = ((ClientTag)dataGridView1.Rows[j].Tag); if (!tag3.updated) { dataGridView1.Rows.RemoveAt(j); } } noClientLabel.Visible = dataGridView1.Rows.Count == 0; var autoConnect = clientList.GetAutoConnectableClient(); if (autoConnect != null) { Connect(autoConnect); } }