How display images in datagridview? c#












4















I am developing an application in C # for desktop using Visual Studio Express 2010.



I have a table in MySQL called Products with 3 fields:




ID -> Product_Name -> product_image




The field product_Image stores the image path in my hard drive (not the image itself)



An example of a record would be:




0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg




I wonder how fill a datagridview that shows the ID, Produt name, and - especially - the product image for each record in my SQL query.



All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.



Edit:



Thank you for help, but could not directly apply the solutions.



I already have a datagridview on my form, I have no need to create in runtime.



I need something like that (I'll write a generic way)



returnMySQL = "select * from products";

while (returnMySQL)
{
    fill datagrid with ID, product name, product image
}









share|improve this question

























  • Do you have all 3 three values in one attribute?

    – Shaharyar
    May 28 '13 at 5:29











  • you need to store the image path in database and need to store image itself into a folder in your project and just apply a select query and bind your datagridview with normal query,

    – Rahul
    May 28 '13 at 5:30
















4















I am developing an application in C # for desktop using Visual Studio Express 2010.



I have a table in MySQL called Products with 3 fields:




ID -> Product_Name -> product_image




The field product_Image stores the image path in my hard drive (not the image itself)



An example of a record would be:




0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg




I wonder how fill a datagridview that shows the ID, Produt name, and - especially - the product image for each record in my SQL query.



All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.



Edit:



Thank you for help, but could not directly apply the solutions.



I already have a datagridview on my form, I have no need to create in runtime.



I need something like that (I'll write a generic way)



returnMySQL = "select * from products";

while (returnMySQL)
{
    fill datagrid with ID, product name, product image
}









share|improve this question

























  • Do you have all 3 three values in one attribute?

    – Shaharyar
    May 28 '13 at 5:29











  • you need to store the image path in database and need to store image itself into a folder in your project and just apply a select query and bind your datagridview with normal query,

    – Rahul
    May 28 '13 at 5:30














4












4








4








I am developing an application in C # for desktop using Visual Studio Express 2010.



I have a table in MySQL called Products with 3 fields:




ID -> Product_Name -> product_image




The field product_Image stores the image path in my hard drive (not the image itself)



An example of a record would be:




0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg




I wonder how fill a datagridview that shows the ID, Produt name, and - especially - the product image for each record in my SQL query.



All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.



Edit:



Thank you for help, but could not directly apply the solutions.



I already have a datagridview on my form, I have no need to create in runtime.



I need something like that (I'll write a generic way)



returnMySQL = "select * from products";

while (returnMySQL)
{
    fill datagrid with ID, product name, product image
}









share|improve this question
















I am developing an application in C # for desktop using Visual Studio Express 2010.



I have a table in MySQL called Products with 3 fields:




ID -> Product_Name -> product_image




The field product_Image stores the image path in my hard drive (not the image itself)



An example of a record would be:




0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg




I wonder how fill a datagridview that shows the ID, Produt name, and - especially - the product image for each record in my SQL query.



All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.



Edit:



Thank you for help, but could not directly apply the solutions.



I already have a datagridview on my form, I have no need to create in runtime.



I need something like that (I'll write a generic way)



returnMySQL = "select * from products";

while (returnMySQL)
{
    fill datagrid with ID, product name, product image
}






c# database winforms datagrid datagridview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 28 '13 at 6:10







Reboot

















asked May 28 '13 at 5:24









RebootReboot

23116




23116













  • Do you have all 3 three values in one attribute?

    – Shaharyar
    May 28 '13 at 5:29











  • you need to store the image path in database and need to store image itself into a folder in your project and just apply a select query and bind your datagridview with normal query,

    – Rahul
    May 28 '13 at 5:30



















  • Do you have all 3 three values in one attribute?

    – Shaharyar
    May 28 '13 at 5:29











  • you need to store the image path in database and need to store image itself into a folder in your project and just apply a select query and bind your datagridview with normal query,

    – Rahul
    May 28 '13 at 5:30

















Do you have all 3 three values in one attribute?

– Shaharyar
May 28 '13 at 5:29





Do you have all 3 three values in one attribute?

– Shaharyar
May 28 '13 at 5:29













you need to store the image path in database and need to store image itself into a folder in your project and just apply a select query and bind your datagridview with normal query,

– Rahul
May 28 '13 at 5:30





you need to store the image path in database and need to store image itself into a folder in your project and just apply a select query and bind your datagridview with normal query,

– Rahul
May 28 '13 at 5:30












3 Answers
3






active

oldest

votes


















8














Use following Code:



Bitmap img;

img = new Bitmap(@"c:imagesmousepad.jpg");

// Create the DGV with an Image column

DataGridView dgv = new DataGridView();

this.Controls.Add(dgv);

DataGridViewImageColumn imageCol = new DataGridViewImageColumn();

dgv.Columns.Add(imageCol);

// Add a row and set its value to the image

dgv.Rows.Add();

dgv.Rows[0].Cells[0].Value = img;


Referance LINK .






share|improve this answer


























  • I guess this is winform coz of desktop tag

    – V4Vendetta
    May 28 '13 at 5:36











  • coze of datagridview not gridview

    – Ria
    May 28 '13 at 5:38











  • @Ria sorry, i edited it.

    – Freelancer
    May 28 '13 at 5:39











  • @V4Vendetta thanks for pointing it out.

    – Freelancer
    May 28 '13 at 5:39



















1














You can add images with the following way:



//you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
string path = @"c:imagesmousepad.jpg";
string ID = "0001";
string Product_Name = "Mousepad XYZ";
dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));





share|improve this answer































    0














    You can Doing this simple way



                SqlConnection conn=New   SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
    SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
    DataTable dt = new System.Data.DataTable();
    adpt.Fill(dt);
    int count = dt.Rows.Count;

    dataGridView1.DataSource = dt;


    thats All you can change Datagrid view height and with according your requirment






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16784440%2fhow-display-images-in-datagridview-c-sharp%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      8














      Use following Code:



      Bitmap img;

      img = new Bitmap(@"c:imagesmousepad.jpg");

      // Create the DGV with an Image column

      DataGridView dgv = new DataGridView();

      this.Controls.Add(dgv);

      DataGridViewImageColumn imageCol = new DataGridViewImageColumn();

      dgv.Columns.Add(imageCol);

      // Add a row and set its value to the image

      dgv.Rows.Add();

      dgv.Rows[0].Cells[0].Value = img;


      Referance LINK .






      share|improve this answer


























      • I guess this is winform coz of desktop tag

        – V4Vendetta
        May 28 '13 at 5:36











      • coze of datagridview not gridview

        – Ria
        May 28 '13 at 5:38











      • @Ria sorry, i edited it.

        – Freelancer
        May 28 '13 at 5:39











      • @V4Vendetta thanks for pointing it out.

        – Freelancer
        May 28 '13 at 5:39
















      8














      Use following Code:



      Bitmap img;

      img = new Bitmap(@"c:imagesmousepad.jpg");

      // Create the DGV with an Image column

      DataGridView dgv = new DataGridView();

      this.Controls.Add(dgv);

      DataGridViewImageColumn imageCol = new DataGridViewImageColumn();

      dgv.Columns.Add(imageCol);

      // Add a row and set its value to the image

      dgv.Rows.Add();

      dgv.Rows[0].Cells[0].Value = img;


      Referance LINK .






      share|improve this answer


























      • I guess this is winform coz of desktop tag

        – V4Vendetta
        May 28 '13 at 5:36











      • coze of datagridview not gridview

        – Ria
        May 28 '13 at 5:38











      • @Ria sorry, i edited it.

        – Freelancer
        May 28 '13 at 5:39











      • @V4Vendetta thanks for pointing it out.

        – Freelancer
        May 28 '13 at 5:39














      8












      8








      8







      Use following Code:



      Bitmap img;

      img = new Bitmap(@"c:imagesmousepad.jpg");

      // Create the DGV with an Image column

      DataGridView dgv = new DataGridView();

      this.Controls.Add(dgv);

      DataGridViewImageColumn imageCol = new DataGridViewImageColumn();

      dgv.Columns.Add(imageCol);

      // Add a row and set its value to the image

      dgv.Rows.Add();

      dgv.Rows[0].Cells[0].Value = img;


      Referance LINK .






      share|improve this answer















      Use following Code:



      Bitmap img;

      img = new Bitmap(@"c:imagesmousepad.jpg");

      // Create the DGV with an Image column

      DataGridView dgv = new DataGridView();

      this.Controls.Add(dgv);

      DataGridViewImageColumn imageCol = new DataGridViewImageColumn();

      dgv.Columns.Add(imageCol);

      // Add a row and set its value to the image

      dgv.Rows.Add();

      dgv.Rows[0].Cells[0].Value = img;


      Referance LINK .







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 28 '13 at 5:40

























      answered May 28 '13 at 5:34









      FreelancerFreelancer

      7,72873273




      7,72873273













      • I guess this is winform coz of desktop tag

        – V4Vendetta
        May 28 '13 at 5:36











      • coze of datagridview not gridview

        – Ria
        May 28 '13 at 5:38











      • @Ria sorry, i edited it.

        – Freelancer
        May 28 '13 at 5:39











      • @V4Vendetta thanks for pointing it out.

        – Freelancer
        May 28 '13 at 5:39



















      • I guess this is winform coz of desktop tag

        – V4Vendetta
        May 28 '13 at 5:36











      • coze of datagridview not gridview

        – Ria
        May 28 '13 at 5:38











      • @Ria sorry, i edited it.

        – Freelancer
        May 28 '13 at 5:39











      • @V4Vendetta thanks for pointing it out.

        – Freelancer
        May 28 '13 at 5:39

















      I guess this is winform coz of desktop tag

      – V4Vendetta
      May 28 '13 at 5:36





      I guess this is winform coz of desktop tag

      – V4Vendetta
      May 28 '13 at 5:36













      coze of datagridview not gridview

      – Ria
      May 28 '13 at 5:38





      coze of datagridview not gridview

      – Ria
      May 28 '13 at 5:38













      @Ria sorry, i edited it.

      – Freelancer
      May 28 '13 at 5:39





      @Ria sorry, i edited it.

      – Freelancer
      May 28 '13 at 5:39













      @V4Vendetta thanks for pointing it out.

      – Freelancer
      May 28 '13 at 5:39





      @V4Vendetta thanks for pointing it out.

      – Freelancer
      May 28 '13 at 5:39













      1














      You can add images with the following way:



      //you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
      string path = @"c:imagesmousepad.jpg";
      string ID = "0001";
      string Product_Name = "Mousepad XYZ";
      dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));





      share|improve this answer




























        1














        You can add images with the following way:



        //you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
        string path = @"c:imagesmousepad.jpg";
        string ID = "0001";
        string Product_Name = "Mousepad XYZ";
        dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));





        share|improve this answer


























          1












          1








          1







          You can add images with the following way:



          //you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
          string path = @"c:imagesmousepad.jpg";
          string ID = "0001";
          string Product_Name = "Mousepad XYZ";
          dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));





          share|improve this answer













          You can add images with the following way:



          //you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
          string path = @"c:imagesmousepad.jpg";
          string ID = "0001";
          string Product_Name = "Mousepad XYZ";
          dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 28 '13 at 5:43









          ShaharyarShaharyar

          9,88622949




          9,88622949























              0














              You can Doing this simple way



                          SqlConnection conn=New   SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
              SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
              DataTable dt = new System.Data.DataTable();
              adpt.Fill(dt);
              int count = dt.Rows.Count;

              dataGridView1.DataSource = dt;


              thats All you can change Datagrid view height and with according your requirment






              share|improve this answer




























                0














                You can Doing this simple way



                            SqlConnection conn=New   SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
                SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
                DataTable dt = new System.Data.DataTable();
                adpt.Fill(dt);
                int count = dt.Rows.Count;

                dataGridView1.DataSource = dt;


                thats All you can change Datagrid view height and with according your requirment






                share|improve this answer


























                  0












                  0








                  0







                  You can Doing this simple way



                              SqlConnection conn=New   SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
                  SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
                  DataTable dt = new System.Data.DataTable();
                  adpt.Fill(dt);
                  int count = dt.Rows.Count;

                  dataGridView1.DataSource = dt;


                  thats All you can change Datagrid view height and with according your requirment






                  share|improve this answer













                  You can Doing this simple way



                              SqlConnection conn=New   SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
                  SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
                  DataTable dt = new System.Data.DataTable();
                  adpt.Fill(dt);
                  int count = dt.Rows.Count;

                  dataGridView1.DataSource = dt;


                  thats All you can change Datagrid view height and with according your requirment







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 22 '17 at 10:58









                  Gayan Chinthaka DharmarathnaGayan Chinthaka Dharmarathna

                  95116




                  95116






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16784440%2fhow-display-images-in-datagridview-c-sharp%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas