Luis
Luis

Reputation: 2715

datagridview dynamic with image

I need a little help to create a datagridview dynamically.

The objective is to ping a list of IP or HostName's success and inserted in the grid (host, date, and Image (Red or Green)) depending on response.

I have this function that writes the grid, but I have a problem if one ping is not successful he puts all others with Redball.

Heres the code i'm using http://codepaste.net/yq1pu9

Upvotes: 0

Views: 505

Answers (2)

KafMigadito
KafMigadito

Reputation: 28

  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();
}

Upvotes: 1

JWiley
JWiley

Reputation: 3219

Did you uncomment all the GridView1.Rows.Add lines for testing purposes?

I noticed that in all three blocks where you add rows to your DataGridView, you're always sending GridView1.Rows.Add(pictureRed, TextboxHost.Text, TextboxWhen.Text);

Did you mean to have something like GridView1.Rows.Add(pictureGreen, TextboxHost.Text, TextboxWhen.Text); under your if (Reply.Status == IPStatus.Success) block?

Upvotes: 0

Related Questions