Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Replace text with image in DataGridView

Replace text with image in DataGridView

Scheduled Pinned Locked Moved Windows Forms
csharpwinformstutorial
4 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 15242671
    wrote on last edited by
    #1

    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.

    L 2 Replies Last reply
    0
    • M Member 15242671

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Display Images in Cells of DataGridView Control - Windows Forms .NET Framework | Microsoft Docs[^]

      M 1 Reply Last reply
      0
      • M Member 15242671

        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.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • L Lost User

          Display Images in Cells of DataGridView Control - Windows Forms .NET Framework | Microsoft Docs[^]

          M Offline
          M Offline
          Member 15242671
          wrote on last edited by
          #4

          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]; } }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups