我开发了一个应用程序,其中dataGridView每秒更新一次。我正在启用两个滚动条。向下和向上的垂直滚动条按钮未显示。我无法滚动垂直滚动条。此外,如果我启用显示最后一行作为第一个滚动索引应用程序挂起。
当我在Visual Studio环境中运行应用程序时,它工作正常。只有当我执行外部Visual Studio环境时,我才会观察到这种行为。
请在下面找到网格更新代码。
private static void UpdateGrid(DataTable table)
{
JSONTest form = (JSONTest)Application.OpenForms["JSONTest"];
if (form.GridTestReport.InvokeRequired)
{
UpdateGridThreadHandler handler = UpdateGrid11;
form.GridTestReport.BeginInvoke(handler, table);
}
else
{
form.GridTestReport.DataSource = table;
}
}
private static void UpdateGridView()
{
JSONTest form = (JSONTest)Application.OpenForms["JSONTest"];
if (form.GridTestReport.InvokeRequired)
{
UpdateGridViewCallback d = new UpdateGridViewCallback(UpdateGridView);
form.GridTestReport.Invoke(d);
}
else
{
foreach (DataGridViewRow row in form.GridTestReport.Rows)
{
if (row.Cells[2].Value.ToString() == "FAIL")
{
row.DefaultCellStyle.ForeColor = Color.Red;
}
else
{
row.DefaultCellStyle.ForeColor = Color.Green;
}
row.Cells["RowNumber"].Value = row.Index + 1;
}
//if (form.GridTestReport.RowCount > 5)
//{
// form.GridTestReport.FirstDisplayedScrollingRowIndex = form.GridTestReport.RowCount - 1;
//}
form.lbl_Response.Text = "Received Response :" + TestSuitADU.countReceivedResponse.ToString();
form.lbl_Request.Text = "Sent Request:" + RandomExecution.CountRequest.ToString();
if (form.TestClasses_combox.SelectedItem == "Batch")
{
form.lbl_Request.Text = "Sent Request:" + TestSuitADU.CountRequestResponse.ToString();
}
}
}