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. Visual Basic
  4. how to display image from gridview on picturebox

how to display image from gridview on picturebox

Scheduled Pinned Locked Moved Visual Basic
helpcomtutorialquestion
9 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.
  • R Offline
    R Offline
    romo22
    wrote on last edited by
    #1

    Hi guys I'm not able to display image from tablegridview to picturebox visual basic 2010 studio. I know how to reference text value from a cell on tablegridview to textbox I had been created . this the Code how to do this :

    TextBox2.Text = Table1DataGridView.Rows(0).Cells(3).Value.ToString

    my question is how to do it with image if you have this image on Table1DataGridView I tried this code for image but it doesn't work I got error

    PictureBox1.image=Table1DataGridView.Rows(0).Cells(2).Value.Toimage

    or

    PictureBox1.image=Table1DataGridView.Rows(0).Cells(2).Value

    both of these cod not work and I get error please Help I hope that some one can solve this complex problem and i will be great full for you . mju10ht@gmail.com

    L 1 Reply Last reply
    0
    • R romo22

      Hi guys I'm not able to display image from tablegridview to picturebox visual basic 2010 studio. I know how to reference text value from a cell on tablegridview to textbox I had been created . this the Code how to do this :

      TextBox2.Text = Table1DataGridView.Rows(0).Cells(3).Value.ToString

      my question is how to do it with image if you have this image on Table1DataGridView I tried this code for image but it doesn't work I got error

      PictureBox1.image=Table1DataGridView.Rows(0).Cells(2).Value.Toimage

      or

      PictureBox1.image=Table1DataGridView.Rows(0).Cells(2).Value

      both of these cod not work and I get error please Help I hope that some one can solve this complex problem and i will be great full for you . mju10ht@gmail.com

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

      Try something like this;

      PictureBox1.image = CType(Table1DataGridView.Rows(0).Cells(2).Value, Bitmap)

      Bastard Programmer from Hell :suss:

      R 1 Reply Last reply
      0
      • L Lost User

        Try something like this;

        PictureBox1.image = CType(Table1DataGridView.Rows(0).Cells(2).Value, Bitmap)

        Bastard Programmer from Hell :suss:

        R Offline
        R Offline
        romo22
        wrote on last edited by
        #3

        thank you for help, but I still get error show me this : Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Bitmap'. I wonder if that code work to you, so that means the code will be correct and I did something wrong :confused: please I need help

        L 1 Reply Last reply
        0
        • R romo22

          thank you for help, but I still get error show me this : Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Bitmap'. I wonder if that code work to you, so that means the code will be correct and I did something wrong :confused: please I need help

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

          Dim bytes as Byte() = ' Your value from the grid goes here
          Using ms as new MemoryStream(bytes)
          Dim img As Bitmap = CType(Image.FromStream(ms), Bitmap)
          PictureBox1.Image = img
          End Using

          Bastard Programmer from Hell :suss:

          R 1 Reply Last reply
          0
          • L Lost User

            Dim bytes as Byte() = ' Your value from the grid goes here
            Using ms as new MemoryStream(bytes)
            Dim img As Bitmap = CType(Image.FromStream(ms), Bitmap)
            PictureBox1.Image = img
            End Using

            Bastard Programmer from Hell :suss:

            R Offline
            R Offline
            romo22
            wrote on last edited by
            #5

            I don't why he put blue line under MemoryStream(bytes)

            Dim bytes As Byte() = Table5DataGridView.Rows(0).Cells(3).Value
            Using ms As New MemoryStream(bytes)
            Dim img As Bitmap = CType(Image.FromStream(ms), Bitmap)
            PictureBox1.Image = img
            End Using

            on error list show me MemoryStream(bytes)is not defined :(

            L 1 Reply Last reply
            0
            • R romo22

              I don't why he put blue line under MemoryStream(bytes)

              Dim bytes As Byte() = Table5DataGridView.Rows(0).Cells(3).Value
              Using ms As New MemoryStream(bytes)
              Dim img As Bitmap = CType(Image.FromStream(ms), Bitmap)
              PictureBox1.Image = img
              End Using

              on error list show me MemoryStream(bytes)is not defined :(

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

              Prefix it with the correct namespace, like this;

              Using ms As New System.IO.MemoryStream(bytes)

              ..or Import the namespace :)

              Bastard Programmer from Hell :suss:

              R 1 Reply Last reply
              0
              • L Lost User

                Prefix it with the correct namespace, like this;

                Using ms As New System.IO.MemoryStream(bytes)

                ..or Import the namespace :)

                Bastard Programmer from Hell :suss:

                R Offline
                R Offline
                romo22
                wrote on last edited by
                #7

                :-D finally yes it's work how can I say thank you for your help .. but you know what you are my super hero who save my time after two days of stupid attempts went fail. oh my God why I didn't ask you from the first day i got this problem, I have a project and this project depends on this code otherwise I will stop work on this project after I faced this problem but now I'm very excited to back work on my project :rose::rose::rose: :rolleyes:

                L 1 Reply Last reply
                0
                • R romo22

                  :-D finally yes it's work how can I say thank you for your help .. but you know what you are my super hero who save my time after two days of stupid attempts went fail. oh my God why I didn't ask you from the first day i got this problem, I have a project and this project depends on this code otherwise I will stop work on this project after I faced this problem but now I'm very excited to back work on my project :rose::rose::rose: :rolleyes:

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

                  You're welcome :)

                  L 1 Reply Last reply
                  0
                  • L Lost User

                    You're welcome :)

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

                    Nicely done

                    Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

                    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