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. C#
  4. DataGridViewImageColumn

DataGridViewImageColumn

Scheduled Pinned Locked Moved C#
cssgraphicstutorialquestion
7 Posts 2 Posters 0 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.
  • E Offline
    E Offline
    e_LA
    wrote on last edited by
    #1

    Hi Is it possible to show different image in one column in each row depending on status of other column in the grid? For example: stop o running ~ waiting x I wouldn't like to create my own class representing ImageCell. Just using CellPainting event. I do like this in CellPainting: e.Graphics.DrawImage(img, e.CellBounds); img depends on value of another column (status) ...but it doesn't work. Image is drawn and disappears Thanks Ela

    J 1 Reply Last reply
    0
    • E e_LA

      Hi Is it possible to show different image in one column in each row depending on status of other column in the grid? For example: stop o running ~ waiting x I wouldn't like to create my own class representing ImageCell. Just using CellPainting event. I do like this in CellPainting: e.Graphics.DrawImage(img, e.CellBounds); img depends on value of another column (status) ...but it doesn't work. Image is drawn and disappears Thanks Ela

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      e_LA wrote:

      Image is drawn and disappears

      It's hard to help you without seeing the context of the drawing code. If it's drawn but then disappears, either you're drawing code is wrong or you're drawing in the wrong place.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      E 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        e_LA wrote:

        Image is drawn and disappears

        It's hard to help you without seeing the context of the drawing code. If it's drawn but then disappears, either you're drawing code is wrong or you're drawing in the wrong place.

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        E Offline
        E Offline
        e_LA
        wrote on last edited by
        #3

        Ok When I put only such a code in cellpainting event private void myDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex > -1 && e.RowIndex > -1) { Image img = global::MyApplication.Properties.Resources.GreenImage; e.Graphics.DrawImage(img, e.CellBounds); } } Anything is drawn. Why? In fact it is drawn and dissapears - I checked it. What is wrong?

        J 1 Reply Last reply
        0
        • E e_LA

          Ok When I put only such a code in cellpainting event private void myDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex > -1 && e.RowIndex > -1) { Image img = global::MyApplication.Properties.Resources.GreenImage; e.Graphics.DrawImage(img, e.CellBounds); } } Anything is drawn. Why? In fact it is drawn and dissapears - I checked it. What is wrong?

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          Instead of setting up a CellPainting handler, define a DataGridViewCell type and override the Paint method, then put your painting code inside that overridden method.

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          E 3 Replies Last reply
          0
          • J Judah Gabriel Himango

            Instead of setting up a CellPainting handler, define a DataGridViewCell type and override the Paint method, then put your painting code inside that overridden method.

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            E Offline
            E Offline
            e_LA
            wrote on last edited by
            #5

            What is a difference between overriding the Paint method and setting up a CellPaining handler? Can I define a DataGridViewCell type and add it to an existing column? Thanks for help Ela

            1 Reply Last reply
            0
            • J Judah Gabriel Himango

              Instead of setting up a CellPainting handler, define a DataGridViewCell type and override the Paint method, then put your painting code inside that overridden method.

              Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

              E Offline
              E Offline
              e_LA
              wrote on last edited by
              #6

              Ok I defined my own class representing column and cell class where I overriden a Paint method. In the Paint method I would like to draw image depending on value of another column. I have to take DataSource (DataView) where I could check the value in another column in the same row (RowIndex). That's why I created cell constructor like that public ImageCell(DataGridView dGridV) { this.grid = dGridV; } When in Paint method I put such a line DataView dv = (DataView)grid.DataSource; I have an exception because grid is null. I think during adding column to grid operation default constructor of the cell is called (which is empty in my case). Am I right? Thanks Ela

              1 Reply Last reply
              0
              • J Judah Gabriel Himango

                Instead of setting up a CellPainting handler, define a DataGridViewCell type and override the Paint method, then put your painting code inside that overridden method.

                Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                E Offline
                E Offline
                e_LA
                wrote on last edited by
                #7

                Yes, it works now. I have only message on Console window: FormattedValueType property of a cell cannot be null. I tried to override FormattedValueType property but it doesn't not works. Another thing is sometimes I have to display animated gif in the cell. However when I want to animate gif I have to call Invalidate method which does not exist for the cell. Thanks Ela

                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