显示数据在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);
}
}