-2

I'm working on a project where I need a picture in to a datagridview by an URL form internet. I can't find out how to do it? Does anyone know how do do it. the project im makeing is in c# WPF. and im useing a mysql database.

Jdiehl
  • 201
  • 3
  • 14

1 Answers1

0

You could use a model and a DataGridTemplateColumn and do something like this:

       <DataGrid Name="DataGrid">
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="{Binding Path}" Height="100"></Image>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>
                <DataGridTextColumn Binding="{Binding Name}"></DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>

MainWindow.cs

public partial class MainWindow : Window
{
    public List<Picture> Pictures { get; set; }
    public MainWindow()
    {
        InitializeComponent();
        Pictures = new List<Picture>()
        {
            new Picture("https://images.askmen.com/1080x540/2017/01/06-044621-the_pitfalls_of_dating_a_married_woman.jpg", "Girl 1"),
            new Picture("https://images.pexels.com/photos/733872/pexels-photo-733872.jpeg?cs=srgb&dl=beautiful-blur-blurred-background-733872.jpg&fm=jpg", "Girl 2")
        };

        DataGrid.ItemsSource = Pictures;
    }
}

Picture Model

public class Picture
{
    public Picture(string path, string name)
    {
        Path = path;
        Name = name;
    }
    public string Path { get; set; }

    public string Name { get; set; }
}
Clemens
  • 123,504
  • 12
  • 155
  • 268
3xGuy
  • 2,235
  • 2
  • 29
  • 51