How display images in datagridview? c#

前端 未结 3 632
情深已故
情深已故 2020-12-19 10:22

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

相关标签:
3条回答
  • 2020-12-19 10:44

    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:\images\mousepad.jpg";
    string ID = "0001";
    string Product_Name = "Mousepad XYZ";
    dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));
    
    0 讨论(0)
  • 2020-12-19 10:50

    Use following Code:

    Bitmap img;
    
    img = new Bitmap(@"c:\images\mousepad.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 .

    0 讨论(0)
  • 2020-12-19 10:52

    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

    0 讨论(0)
提交回复
热议问题