如何仅显示已过滤的数据 [英] How to show only filtered data

查看:78
本文介绍了如何仅显示已过滤的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,大家早上好。我想在我的表中只显示过滤记录如何可能我的当前代码显示突出显示的过滤记录与其他非过滤记录。这怎么可能。

  private   void  textBox2_TextChanged( object  sender,EventArgs e)
{
try
{
this .dataGridView1.ClearSelection();
foreach (DataGridViewRow r in this .dataGridView1.Rows)
{
if (r.Cells [ 1 ]。值!= null
{
if ((r。单元格[ 1 ]。值).ToString()。StartsWith( this .textBox2.Text.Trim( )))
{
this .dataGridView1.Rows [r.Index] .Selected = true ;
}
}
}
}
catch (例外情况)
{
MessageBox.Show(ex.ToString());
}
}

私有 void dataGridView1_DataBindingComplete( object sender,DataGridViewBindingCompleteEventArgs e)
{
dataGridView1.ClearSelection();
}

解决方案

在这里您可以获得一些见解:C#过滤datagridview [ ^ ]。

Hi, guys good morning. I want to display only filtered record in my table how this is possible my current code show the highlighted filtered record with other non filtered record. How this is possible.

private void textBox2_TextChanged(object sender, EventArgs e)
       {
           try
           {
               this.dataGridView1.ClearSelection();
               foreach (DataGridViewRow r in this.dataGridView1.Rows)
               {
                   if (r.Cells[1].Value != null)
                   {
                       if ((r.Cells[1].Value).ToString().StartsWith(this.textBox2.Text.Trim()))
                       {
                           this.dataGridView1.Rows[r.Index].Selected = true;
                       }
                   }
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.ToString());
            }
        }

        private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dataGridView1.ClearSelection();
        }

解决方案

Here you may get some insight: "C# filtering datagridview"[^].


这篇关于如何仅显示已过滤的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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