0
我有一個綁定列表和源鏈接到我的DataGridView。在DataGridView單元格中顯示來自web的圖像
當我添加一個項目到我的綁定列表中時,我想在單元格中顯示該圖像(來自網頁)。這可能嗎?
這是我到目前爲止,我能夠從網頁加載圖像,但我不知道如何來顯示它的DataGridView行的第一列:
public partial class Form1 : Form
{
static BindingList<VideoInfo> searchResults = new BindingList<VideoInfo>();
BindingSource bindingSearchResults = new BindingSource()
{
DataSource = searchResults
};
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
resultGrid.DataSource = bindingSearchResults;
}
private void button1_Click(object sender, EventArgs e)
{
searchResults.Add(new VideoInfo()
{
Thumbnail = DownloadImage("http://i.ytimg.com/vi/uJbDSPRqX0o/mqdefault.jpg"),
Title = "Man's Best Friend - Cyanide & Happiness Shorts",
Url = "http://www.youtube.com/watch?v=uJbDSPRqX0o "
});
}
private Image DownloadImage(string imageUrl)
{
try
{
WebRequest req = WebRequest.Create(imageUrl);
return Image.FromStream(req.GetResponse().GetResponseStream());
}
catch { }
return new Bitmap(1, 1);
}
}
public struct VideoInfo
{
public Image Thumbnail { get; set; }
public string Title { get; set; }
public string Url { get; set; }
}
您是否解決了您的問題? – TaW 2015-02-17 22:04:51