简体   繁体   English

Datagridview没有选择最后一行

[英]Datagridview not selecting last row

I am selecting records from a datagridview... I have got 5 rows in this datgridview and I am trying to select each and everyone of them by a click of a buton(NextrecordButton). 我正在从datagridview中选择记录...在此datgridview中有5行,我试图通过单击按钮(NextrecordButton)来选择每一个。 This is working well but I am running into a problem the only 4 rows are selected and the last row isn't selected. 这工作得很好,但是我遇到一个问题,仅选择了4行,而未选择最后一行。 is there anything am doing wrong in my code below: 我的代码下面有什么地方做错了吗?

private void btnNext_Click(object sender, EventArgs e)
{
   if (EmpCounter < dataset.Tables[0].Rows.Count - 1)
   {
      TxtDisplay.Text = dataset.Tables[0].Rows[EmpCounter]["Emp_Name"].ToString();
   }
}

This is working well but I am running into a problem the only 4 rows are selected and the last row isn't selected. 这工作得很好,但是我遇到一个问题,仅选择了4行,而未选择最后一行。

Because your check is checking till second last row 因为您的支票要检查到倒数第二行

EmpCounter < dataset.Tables[0].Rows.Count - 1

It should be: 它应该是:

EmpCounter < dataset.Tables[0].Rows.Count

So your code should be: 因此,您的代码应为:

private void btnNext_Click(object sender, EventArgs e)
{
    if (EmpCounter < dataset.Tables[0].Rows.Count)
    {
        TxtDisplay.Text = dataset.Tables[0].Rows[EmpCounter]["Emp_Name"].ToString();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM