datagridview动态与图像
我需要一些帮助来动态创建datagridview。
目标是ping一个IP或HostName成功列表并插入网格(主机,日期和图像(红色或绿色)),具体取决于响应。
我有这个写入网格的function,但如果一个ping不成功,我就会遇到问题,所有其他人都使用Redball。
inheritance人我正在使用的代码http://codepaste.net/yq1pu9
private void TabelaDinamimcaSucess(bool sucesso, int index, string host, string data, string tempo,string status) { string[] row = new string[] { index.ToString(), host, data, tempo,status }; dataGridView1.Rows.Add(row); int number_of_rows = dataGridView1.RowCount -1; Bitmap b = new Bitmap((sucesso == true ? Properties.Resources.greenBall : Properties.Resources.redBall)); Icon icon = Icon.FromHandle(b.GetHicon()); dataGridView1.Rows[number_of_rows].Cells["img"].Value = icon; dataGridView1.Show(); }
您是否取消注释所有GridView1.Rows.Add
行以进行测试?
我注意到在你向DataGridView
添加行的所有三个块中,你总是发送GridView1.Rows.Add(
pictureRed , TextboxHost.Text, TextboxWhen.Text);
你的意思是像GridView1.Rows.Add(
pictureGreen , TextboxHost.Text, TextboxWhen.Text);
在你的if (Reply.Status == IPStatus.Success)
块下?