因此,我有一个DataGridViewwhere,我正在从我的Access数据库填充信息。DataGridView的第一列显示为来自我的网络的IP。我尝试做的是使用键盘上的上下箭头,将每一行的信息显示到几个TextBox中。代码如下:
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
bool pingable = false;
Ping pinger = new Ping();
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
PingReply reply = pinger.Send(row.Cells[0].Value.ToString());
if (e.KeyCode == Keys.Down)
{
txtIP.Text = row.Cells[0].Value.ToString();
txtUser.Text = row.Cells[1].Value.ToString();
txtComputer.Text = row.Cells[2].Value.ToString();
txtUnity.Text = row.Cells[3].Value.ToString();
txtSession.Text = row.Cells[4].Value.ToString();
if (pingable = reply.Status == IPStatus.Success)
{
pictureBoxGreen.Show();
pictureBoxRed.Hide();
}
else if (pingable = reply.Status == IPStatus.TimedOut)
{
pcGreen.Hide();
pcRed.Show();
}
}
if (e.KeyCode == Keys.Up)
{
txtIP.Text = row.Cells[0].Value.ToString();
txtUser.Text = row.Cells[1].Value.ToString();
txtComputer.Text = row.Cells[2].Value.ToString();
txtUnity.Text = row.Cells[3].Value.ToString();
txtSession.Text = row.Cells[4].Value.ToString();
if (pingable = reply.Status == IPStatus.Success)
{
pictureBoxGreen.Show();
pictureBoxRed.Hide();
}
else if (pingable = reply.Status == IPStatus.TimedOut)
{
pictureBoxGreen.Hide();
pictureBoxRed.Show();
}
}
}
}问题是,例如,在DataGridView的第一行单击并使用箭头后,它不会显示正确的信息,而是显示上面行的信息。你知道问题出在哪里吗?
https://stackoverflow.com/questions/44648396
复制相似问题