internal FrmUninstallProduct(Computer targetComputer, List <MsiProduct> targetProducts) { InitializeComponent(); _successStyle.BackColor = Color.LawnGreen; _successRebootStyle.BackColor = Color.Orange; _failedStyle.BackColor = Color.Red; TargetComputer = targetComputer; txtBxComputer.Text = targetComputer.ComputerName; foreach (MsiProduct msiProduct in targetProducts) { int index = dgvProducts.Rows.Add(); dgvProducts.Rows[index].Cells["Product"].Value = msiProduct; dgvProducts.Rows[index].Cells["ProductName"].Value = msiProduct.Name; dgvProducts.Rows[index].Cells["Version"].Value = msiProduct.Version; dgvProducts.Rows[index].Cells["InstallDate"].Value = MsiProduct.GetFormattedInstallDate(msiProduct.InstallDate); dgvProducts.Rows[index].Cells["Result"].Value = String.Empty; dgvProducts.Rows[index].Cells["ResultCode"].Value = String.Empty; } }
private void DisplayProductForComputer(Computer computer) { Action displayProductsAction = () => { try { dgvProducts.Rows.Clear(); if (!computer.ProductsRetrievalInProgress) { List <DataGridViewRow> rows = new List <DataGridViewRow>(); if (String.IsNullOrEmpty(txtBxPattern.Text)) { txtBxPattern.Text = "%"; } List <MsiProduct> displayedProducts = FilterInstalledProducts(computer.Products, txtBxPattern.Text, txtBxExceptions.Text); foreach (MsiProduct product in displayedProducts) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgvProducts, new Object[] { product, product.IdentifyingNumber, product.Name, product.Version, MsiProduct.GetFormattedInstallDate(product.InstallDate) }); rows.Add(row); } dgvProducts.Rows.AddRange(rows.ToArray()); dgvProducts.ClearSelection(); UpdateProductCount(computer, displayedProducts.Count); if (dgvProducts.SortedColumn != null) { dgvProducts.Sort(dgvProducts.SortedColumn, dgvProducts.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending); } else { dgvProducts.Sort(dgvProducts.Columns["ProductName"], ListSortDirection.Ascending); } } } catch (Exception) { } }; Invoke(displayProductsAction); }