■58211 / inTopicNo.4) |
Re[3]: DGVImageColumnの表示がおかしい |
□投稿者/ インデックス (6回)-(2011/03/29(Tue) 05:47:20)
|
■No58172 (ヘッタッタ さん) に返信
説明不足でしたすみません、再度纏めてみました。
DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
imageColumn.Name = "imageColumn";
imageColumn.Width = 50;
imageColumn.ImageLayout = DataGridViewImageCellLayout.Zoom;
this.dataGridView1.Columns.Add(imageColumn);
this.dataGridView1.Columns.Add("no", "No");
this.dataGridView1.Columns.Add("come", "コメント");//列の作成
this.dataGridView1.Columns.Add("user_id", "ユーザーID");
while (true)
{
サーバーとの通信処理
・
・
・
this.dataGridView1.Rows.Clear();
backgroundWorker1.RunWorkerAsync();
break;
}
---------------------------------------別スレッド
while(true)
{
データの受信処理
・
・
・
string comecount = "";
string come2 = "";
string user_id = "";
string user_no_tmp = "";
string user_thum_url = "";
string user_thum_check_url = "";
int trim_start_v8 = 0;
int trim_end8 = 4;
xml = xml.Replace('\0', '\n');
var xdoc1 = new XmlDocument();
xdoc1.LoadXml(String.Format("<root>{0}</root>", xml));
foreach (XmlNode ndtmp in xdoc1.ChildNodes)
{
foreach (XmlNode nd in ndtmp.ChildNodes)
{
var attr = nd.Attributes;
if (nd.Name == "chat")
{
come2 = String.Format(nd.InnerText);
comecount = attr["no"].Value;
user_id = attr["user_id"].Value;
}
if (user_id.Length == 8)
{
user_no_tmp = user_id.Substring(trim_start_v8, trim_end8);
}
this.Invoke(new MethodInvoker(delegate
{
dataGridView1.AllowUserToAddRows = true;
}));
DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
imageColumn.Name = "imageColumn";
imageColumn.Width = 50;
switch(user_id.Length)
{
case 8://8ケタ
user_thum_check_url = "http://usericon.nimg.jp/usericon/" + user_no_tmp + "/" + user_id + ".jpg";
HttpStatusCode error_status8=GetStatusCode(user_thum_check_url);
int error_code8 = (int)error_status8;
if (error_code8 == 404)//エラー404の検出
{
user_thum_check_url = "http://uni.res.nimg.jp/img/user/thumb/blank.jpg";
WebClient not_set_image_cl = new WebClient();
Stream not_set_image_str = not_set_image_cl.OpenRead(user_thum_check_url);
Bitmap user_thum_not_found8 = new Bitmap(not_set_image_str);
not_set_image_str.Close();
imageColumn.Image = new Bitmap(user_thum_not_found8);
imageColumn.ImageLayout = DataGridViewImageCellLayout.Zoom;
this.Invoke(new MethodInvoker(delegate
{
this.dataGridView1["imageColumn", 0].Value = new Bitmap(user_thum_not_found8);
this.dataGridView1.Rows.Add(new Bitmap(user_thum_not_found8), comecount, come2, user_id);
this.dataGridView1.AllowUserToAddRows = false;
}));
break;
}
else
{
user_thum_url = "http://usericon.nimg.jp/usericon/" + user_no_tmp + "/" + user_id + ".jpg";
WebClient image_get8 = new WebClient();
Stream image_get_stream8 = image_get8.OpenRead(user_thum_url);
Bitmap user_thum8 = new Bitmap(image_get_stream8);
image_get_stream8.Close();
imageColumn.Image = new Bitmap(user_thum8);
imageColumn.ImageLayout = DataGridViewImageCellLayout.Zoom;
this.Invoke(new MethodInvoker(delegate
{
this.dataGridView1["imageColumn", 0].Value = new Bitmap(user_thum8);
this.dataGridView1.Rows.Add(new Bitmap(user_thum8), comecount, come2, user_id);
this.dataGridView1.AllowUserToAddRows = false;
}));
break;
}
・
・
・
}
}
}
といった流れです。
|
|