0

I have this query which adds peoples email addresses (Friends) but I would like it so that every friend has an avatar so it would look like this:

[Avatar] - Email address

code:

private void loadData()
{
    var query = from o in Globals.DB.Friends
                where o.UserEmail == Properties.Settings.Default.Email
                select new
                {
                    FirstName = o.FirstName,
                    LastName = o.LastName,
                    Email = o.Email,
                    Display = string.Format("{0} {1} - ({2})", o.FirstName, o.LastName, o.Email)
                };
    dataGridView1.DataSource = query.ToList();
}

How would I go about doing that? Because ill have to make a DataGridViewImageCell right?

So something like this?

private void loadData()
{
    DataGridViewImageCell Avatar = new DataGridViewImageCell();

    var query = from o in Globals.DB.Friends
                where o.UserEmail == Properties.Settings.Default.Email
                select new
                {
                    Avatar = o.Avatar,
                    FirstName = o.FirstName,
                    LastName = o.LastName,
                    Email = o.Email,
                    Display = string.Format("{0} {1} {2} - ({3})", o.Avatar, o.FirstName, o.LastName, o.Email)
                };

    dataGridView1.DataSource = query.ToList();
}
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
richardj97
  • 79
  • 1
  • 10
  • `Display` field doesn't make sense. You can not show an image in a string! – Reza Aghaei Jun 24 '16 at 22:12
  • You can show image in a different column simply if you have an image in database. If you want to show image and text in a single column, you should draw it yourself. – Reza Aghaei Jun 24 '16 at 22:13

1 Answers1

0

Please refer https://msdn.microsoft.com/en-us/library/aa479350.aspx. This article gives information using picture URL.

If picture stored in database as BLOB, please refer below detais. Display the image in Datagridview image control

byte[] bytes = (byte[])GetData("SELECT Data FROM tblFiles WHERE Id =" + id).Rows[0]["Data"];
    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
    Image1.ImageUrl = "data:image/png;base64," + base64String;