显示数据在DataGridview中的排序依据 [英] To show data Order by in DataGridview

查看:168
本文介绍了显示数据在DataGridview中的排序依据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,


我的表单中有一个文本框,用于按起始字符显示数据,但它显示包括相同字符在内的所有数据,并且我的代码是

私有void TextBoxName_TextChanged(对象发送者,EventArgs e)

{


DataGridView.FilterName = TextBoxName.Text;
DataGridView.BindGrid();
}



我在文本框中写了一个字母例如:-我写了
文本框中的"A",因此必须显示"A"开头的所有数据字符
所以我可以在数据网格视图中按顺序(按起始字符)获取数据.请plz帮助我解决问题

Hello Sir,


I have a text box in my form to show data by start character but it display all data including same character and my code is

private void TextBoxName_TextChanged(object sender, EventArgs e)

{


DataGridView.FilterName = TextBoxName.Text;
DataGridView.BindGrid();
}



and i write one letter in text box EXAMPLE:-i write
"A" in text box so the all data started character by "A" have to display
so i get data by order(by start Character) in my data grid view.So plz help me and solve my problem

推荐答案

如果我正确理解了您的问题, " d建议使用BindingSource及其过滤器
If I correctly understand your problem, I''d recommend to use BindingSource and it''s filter
public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
      MyDBDataSet ds = new MyDBDataSet();
      BindingSource bs ;

      private void Form1_Load(object sender, EventArgs e)
      {
          MyDBDataSetTableAdapters.ClientsTableAdapter adapter = new WindowsFormsApplication48.MyDBDataSetTableAdapters.ClientsTableAdapter();
          bs = new BindingSource(ds, "Clients");
          adapter.Fill(ds.Clients);
          this.dataGridView1.DataSource = bs;
      }

      private void textBox1_TextChanged(object sender, EventArgs e)
      {
          bs.Filter =String.Format("Customer like ''%{0}%''",textBox1.Text);
      }
  }


这篇关于显示数据在DataGridview中的排序依据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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