void UpdateGrid(bool updateDevices) { lock (updateGridLock) { if (updateDevices) { devices = DeviceDetector.GetDevices().ToList(); interfaces = DeviceDetector.GetInterfaces().ToList(); devices.AddRange(interfaces); } var filter = FilterTextBox.Text.Trim(); var view = devices; if (EnableFilterCheckBox.Checked && !string.IsNullOrEmpty(filter)) { view = devices.Where(x => comp(x.ClassDescription, filter) || comp(x.Description, filter) || comp(x.Manufacturer, filter) || comp(x.DeviceId, filter)) .ToList(); } DeviceDataGridView.DataSource = view; DeviceTabPage.Text = string.Format("{0} Devices on {1:yyyy-MM-dd HH:mm:ss}", view.Count, DateTime.Now); var dis = devices.Where(x => string.IsNullOrEmpty(x.ParentDeviceId)).ToArray(); var classes = devices.Select(x => x.ClassGuid).Distinct(); // Suppress repainting the TreeView until all the objects have been created. DevicesTreeView.Nodes.Clear(); TreeImageList.Images.Clear(); foreach (var cl in classes) { var icon = DeviceDetector.GetClassIcon(cl); if (icon != null) { Image img = new Icon(icon, 16, 16).ToBitmap(); TreeImageList.Images.Add(cl.ToString(), img); } } DevicesTreeView.BeginUpdate(); foreach (DeviceInfo di in dis) { var tn = new TreeNode(System.Environment.MachineName); tn.Tag = di; tn.ImageKey = di.ClassGuid.ToString(); tn.SelectedImageKey = di.ClassGuid.ToString(); DevicesTreeView.Nodes.Add(tn); AddChildren(tn); } DevicesTreeView.EndUpdate(); DevicesTreeView.ExpandAll(); } }