导航仅抛出datagridview C#中的可见行 [英] Navigate throws only visible row in a datagridview C#

查看:75
本文介绍了导航仅抛出datagridview C#中的可见行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用按钮作为导航器来抛出datagridview的可见行,我使用此代码隐藏行:

I want use buttons as navigator to go throw the visible rows of a datagridview,I use this code to hide the rows :

private void Form1_Load(object sender, EventArgs e)

    {

        this.categoriaTableAdapter.Fill(this.mioOilMixDataSet.Categoria);
        for (int item = 0; item < categoriaDataGridView.Rows.Count - 1; item++)




        {
            if (categoriaDataGridView.Rows[item].Cells[2].Value.ToString().Contains("A"))
            {

                CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[categoriaDataGridView.DataSource];
                currencyManager1.SuspendBinding();
                categoriaDataGridView.Rows[item].Visible = true;
                currencyManager1.ResumeBinding();


            }
            else
            {
                CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[categoriaDataGridView.DataSource];
                currencyManager1.SuspendBinding();
                categoriaDataGridView.Rows[item].Visible = false;
                currencyManager1.ResumeBinding();
            }



        }

    }






我的尝试:



和这导航:



What I have tried:

and this to navigate :

private void button1_Click(object sender, EventArgs e)
    {

        foreach (DataGridViewRow row in categoriaDataGridView.Rows)
        {
            if (row.Visible)
            {
                categoriaBindingSource.MoveNext();
                break;
            }

        }



它会转到下一行,但也会显示不可见的行,为什么?


It's go to the next row,but show also the invisible rows,why ?

推荐答案





这是因为记录在网格中,即使你没有看到。方法MoveNext无法控制行的可见性,它移动到网格中的下一条记录,可见或不可见。



做你想做的事。这样做:

Hi,

This happened because the record is in the grid, even though you do not see. The method MoveNext don't have control about the visibility the row, it move for the next record in the grid, visible or not.

To do what you want. Do like this:
private void button1_Click(object sender, EventArgs e)
{
   //find the current position selected
   int indexrow = categoriaBindingSource.Position;

   //read the rows until find the first visible row
   for (int item = indexrow; item < categoriaDataGridView.Rows.Count - 1; item++)
   {
        //verify if the next rows is visible
        if (categoriaDataGridView.Rows[(item + 1)].Visible)
        {
            //move the selector for this position
            categoriaBindingSource.Position = (item + 1);
            break;
        }
   }
}


这篇关于导航仅抛出datagridview C#中的可见行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆