Replace text with image in DataGridView
-
My WinForms project has a DataGridView component which among other things shows PASS/FAIL text data. I would like to replace any "PASS" with a check-mark image and any "FAIL" with a cross image but I'm not sure how to achieve this. Any assistance would be appreciated.
-
My WinForms project has a DataGridView component which among other things shows PASS/FAIL text data. I would like to replace any "PASS" with a check-mark image and any "FAIL" with a cross image but I'm not sure how to achieve this. Any assistance would be appreciated.
-
My WinForms project has a DataGridView component which among other things shows PASS/FAIL text data. I would like to replace any "PASS" with a check-mark image and any "FAIL" with a cross image but I'm not sure how to achieve this. Any assistance would be appreciated.
Use a symbol font with a larger FontSize; e.g. Wingdings. If it's Windows 10, the MS font Segoe MDL2 Assets has the windows icons and Segoe UI Symbol are the "pre" MDL2 icons. And there's Segoe UI Emoji ✅✔☠ for color.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
Thanks. It is working now. I first created an image column. DataGridViewImageColumn iconColumn = new DataGridViewImageColumn(); iconColumn.HeaderText = "Pass/Fail"; iconColumn.Width = 60; iconColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; iconColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; iconColumn.SortMode = DataGridViewColumnSortMode.NotSortable; CalGrid.Columns.Insert(2, iconColumn); I then used the CellFormatting event to set the correct image. private void CalGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (CalGrid[3,e.RowIndex].Value.ToString() == "PASS") { e.Value = imageList1.Images[0]; } else { e.Value = imageList1.Images[1]; } }