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. Display images in Gridview

Display images in Gridview

Scheduled Pinned Locked Moved C#
help
3 Posts 3 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
    Elizabeth Rani
    wrote on last edited by
    #1

    Hi, I need to display images from a particular path, in which the images are not stored in the data base. Can anybody help with some sort of code will be very much helpfull for me. Thanks in advance

    A M 2 Replies Last reply
    0
    • E Elizabeth Rani

      Hi, I need to display images from a particular path, in which the images are not stored in the data base. Can anybody help with some sort of code will be very much helpfull for me. Thanks in advance

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      Try http://msdn.microsoft.com/en-us/library/aa479350.aspx[^].

      1 Reply Last reply
      0
      • E Elizabeth Rani

        Hi, I need to display images from a particular path, in which the images are not stored in the data base. Can anybody help with some sort of code will be very much helpfull for me. Thanks in advance

        M Offline
        M Offline
        Montasser Ben Ouhida
        wrote on last edited by
        #3

        Hi, You can implement the cell paint event. I think that you have a data table like this: (Val1, Val2, PicturePath, ...). You can find bellow an example of code that shows in a data grid view a grid contact: ---------------------------------------------------------------- |Picture | First Name | Last Name | Phone number | ---------------------------------------------------------------- |    ;)   |     Mr. X       |   X1            |  00112233       | ---------------------------------------------------------------- |    ;)   |     Mr. X       |   X1            |  00112233       | ----------------------------------------------------------------

        // Subscribe to the event cell painting
        myDataGridView += new DataGridViewCellPaintingEventHandler(myDataGridView_CellPainting);

        // Implement the event
        void myDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
        // Test if you are drawing the picture cell. Note that the RowIndex == 0 is the row header
        if (e.RowIndex > 0 && e.ColumnIndex == 0)
        {
        try
        {
        string strPath = myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
        // To optimize you program, you can store the loadeds picture in a dictionary like this:
        Bitmap objPicture = null;
        if(dicPictures.ContainsKey(strPath))
        {
        objPicture = dicPictures[strPath];
        }
        else
        {
        objPicture = Bitmap.FromFile(strPath);
        dicPictures.Add(strPath, objPicture);
        }

                 e.Graphics.DrawImage(objPicture, e.CellBounds);
               }
               catch (Exception Error)
               { 
                  // Error Log or Managing
               } 
           }
        

        }

        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