Click here to Skip to main content
15,886,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I want to filter datagridview data by latter or name in c# .net windows application,

How can be possible?

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted
Comments
[no name] 17-May-13 1:14am    
What so you mean by filter..??is it sorting which u r looking for..??
[no name] 17-May-13 1:24am    
ya, your right
Varun Sareen 17-May-13 1:25am    
try to fetch the data from database by using the "ORDER BY [Column Name]" clause where [Column Name] will be the name of the column according to which you want to filter the data and then bind the fetched data to the datagrid.

Thanks & Regards

Varun Sareen
[no name] 17-May-13 1:29am    
I need to just search data according to by name of latter in c$ .net windows application.

You can filter data datagridview in many ways, One the the way is as below :

C#
DataTable dt = new DataTable();
BindingSource bs = new BindingSource();

private void Form1_Load(object sender, EventArgs e)
{
    dt.Columns.Add("id", typeof(int));
    dt.Columns.Add("country", typeof(string));

    dt.Rows.Add(new object[] { 1, "Belgium" });
    dt.Rows.Add(new object[] { 2, "France" });
    dt.Rows.Add(new object[] { 3, "Germany" });
    dt.Rows.Add(new object[] { 4, "Spain" });
    dt.Rows.Add(new object[] { 5, "Swiss" });
    dt.Rows.Add(new object[] { 6, "United Kingdom" });

    bs.DataSource = dt;
    dataGridView1.DataSource = bs;
}

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


For more information refer:
http://stackoverflow.com/questions/5843537/filtering-datagridview-without-changing-datasource[^]

Hope this will help you!!
 
Share this answer
 
v3
You can have a look at this, it should give very good idea of what you should do.

http://msdn.microsoft.com/en-us/library/aa480727.aspx[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900