private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "StarredIcon") { FavoritesIcons icn = (FavoritesIcons)Enum.Parse(typeof(FavoritesIcons), (string)dataGridView1.Rows[e.RowIndex].Cells["Starred"].Value ?? "Silver", true); switch (icn) { case FavoritesIcons.Silver: e.Value = Properties.Resources.silver16_star; break; case FavoritesIcons.Gold: e.Value = Properties.Resources.gold16_star; break; case FavoritesIcons.Blue: e.Value = Properties.Resources.blue16_star; break; case FavoritesIcons.Red: e.Value = Properties.Resources.red16_star; break; } //e.Value = favoritesImageList.Images[(int)icn];// (string)dataGridView1.Rows[e.RowIndex].Cells["Starred"].Value == "Gold" ? Properties.Resources.gold16_star : Properties.Resources.silver16_star; } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0) { FavoritesIcons icn = (FavoritesIcons)Enum.Parse(typeof(FavoritesIcons), (string)dataGridView1.Rows[e.RowIndex].Cells["Starred"].Value ?? "Silver", true); if (icn == FavoritesIcons.Red) { icn = FavoritesIcons.Silver; } else { icn = (FavoritesIcons)(((int)icn) + 1); } var worker = new BackgroundWorker(); panelWait.Visible = true; worker.DoWork += (ssender, es) => { ServiceHelper.UpdateFavorite((Candidate)dataGridView1.Rows[e.RowIndex].DataBoundItem, icn.ToString()); }; worker.RunWorkerCompleted += (ssender, es) => { CrossThreadUtility.InvokeControlAction <DataGridView>(dataGridView1, dg => { dg.Rows[e.RowIndex].Cells["Starred"].Value = icn.ToString(); m_mainGridBindingSource.ResetBindings(true); }); CrossThreadUtility.InvokeControlAction <Panel>(panelWait, p => p.Visible = false); }; worker.RunWorkerAsync(); } }