日期:2014-05-18 浏览次数:21031 次
private void UserInfo_Load(object sender, EventArgs e) { dataGridView2.DataSource = BindGridview(); } private void dataGridView2_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { using (WebClient wc = new WebClient()) { //开始异步下载,图片URL路径请根据实际情况自己去指定 //同时将DataGridView当前行的行号传递过去,用于指定图片显示的CELL wc.DownloadDataAsync(new Uri(dataGridView2.Rows[e.RowIndex].Cells["Column2"].Value.ToString()), e.RowIndex); //WebClient 下载完毕的响应事件绑定 wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted); } } ///<summary> /// 图片下载完毕,显示于对应的CELL /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { ////如果下载过程未发生错误,并且未被中途取消 if (e.Error == null && !e.Cancelled) { ////将图片显示于对应的指定单元格, e.UserState 就是传入的 e.RowIndex ////e.Result 就是下载结果 this.dataGridView2.Rows[(int)e.UserState].Cells["V_httppath"].Value = e.Result; } }