如何从datagridview中获取图像网址并将其放入c#中的图片框中

时间:2022-09-03 23:27:20

Good day

美好的一天

I am needing help

我需要帮助

I want to take an image url that is in a datagridview which is connected to a database and add the url to a picturebox in c#.

我想获取一个连接到数据库的datagridview中的图像URL,并将该URL添加到c#中的图片框中。

I have searched for it but had no luck

我已经搜索过但没有运气

2 个解决方案

#1


0  

You can create picture type cell and put in it pictures. which you can show in Picture box when cell was clicked or entered. Or you can have only URL link in datagrid cells and when you click cell then URL link will be used to get image from.

您可以创建图片类型单元格并将其放入图片中。单击或输入单元格时,您可以在图片框中显示。或者您可以在datagrid单元格中只有URL链接,当您单击单元格时,将使用URL链接从中获取图像。

    private void bt_AddPicture_Click(object sender, EventArgs e)
    {
        //Add image to datagrid view
        //You can add picture from SQL database instead.
        dataGridView1.Rows.Add(Image.FromFile(@"c:\Users\Programmer\Desktop\tmp\tmp\Capture.PNG"));
    }

    private void bt_ShowPicture_Click(object sender, EventArgs e)
    {
        //Show image from datagrid view in picture box.
        //You can use it in event on cellEnter
        pictureBox1.Image = ( dataGridView1.Rows[0].Cells[0].Value as Image);
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    }

#2


0  

I came right

我说得对

    private void dgData_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        picData.ImageLocation = dgData.CurrentRow.Cells[1].Value.ToString();
        picData.SizeMode = PictureBoxSizeMode.StretchImage;
    }

This worked very well

这非常有效

#1


0  

You can create picture type cell and put in it pictures. which you can show in Picture box when cell was clicked or entered. Or you can have only URL link in datagrid cells and when you click cell then URL link will be used to get image from.

您可以创建图片类型单元格并将其放入图片中。单击或输入单元格时,您可以在图片框中显示。或者您可以在datagrid单元格中只有URL链接,当您单击单元格时,将使用URL链接从中获取图像。

    private void bt_AddPicture_Click(object sender, EventArgs e)
    {
        //Add image to datagrid view
        //You can add picture from SQL database instead.
        dataGridView1.Rows.Add(Image.FromFile(@"c:\Users\Programmer\Desktop\tmp\tmp\Capture.PNG"));
    }

    private void bt_ShowPicture_Click(object sender, EventArgs e)
    {
        //Show image from datagrid view in picture box.
        //You can use it in event on cellEnter
        pictureBox1.Image = ( dataGridView1.Rows[0].Cells[0].Value as Image);
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    }

#2


0  

I came right

我说得对

    private void dgData_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        picData.ImageLocation = dgData.CurrentRow.Cells[1].Value.ToString();
        picData.SizeMode = PictureBoxSizeMode.StretchImage;
    }

This worked very well

这非常有效