small-j
small-j

Reputation: 309

Image in Windows Forms DataGridView

I have a Form with a DataGridView. The DataGridView's source is BindingList Here's the Tiger class:

  public class Tiger
{
    public string Name { get; set; }
    public int Weight { get; set; }
    public DateTime Born { get; set; }
    public String Picture { get; set; }

    public Tiger(string name, int weight, DateTime born)
    {
        Name = name;
        Weight = weight;
        Born = born;
        Picture = "D:\\Dropbox\\Uni\\NET\\tigers";
    }
}

I want the Picture column to show the Image with URI in the Picture field, not the string. How can I implement it?

Upvotes: 0

Views: 181

Answers (2)

raBinn
raBinn

Reputation: 182

maybe this code could help you:

        FileStream fs = new System.IO.FileStream(@"Images\a.bmp", FileMode.Open, FileAccess.Read); 
pictureBox1.Image = Image.FromStream(fs);

  fs.Close();

show this link

good luck

Upvotes: 1

Vitor Rigoni
Vitor Rigoni

Reputation: 573

For that, create a column type Image in your datagridview and a byte[] property in your tiger class.

In your constructor, you read the image as a byte[] and set the property.

Use this byte[] property for the Image column in your datagridview

Upvotes: 2

Related Questions