Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello!
From lasttopic i have question about filtering rows DataGridView.
This is link on topic, where you can see how shapes DataGrig:

C#
ListCards.DataSource = BLL.Cards.GetListCards(); (View layer)


At manual MSDN i found following:

C#
BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "yourColumnName like '%" + textBox1.Text + "%'";
dataGridView1.DataSource = bs;

_________________________________
In the first i want to fill Grid and show it: ListCards.DataSource = BLL.Cards.GetListCards();
When i enter text to TextBox i want to do sort by Name Grid and how make it?
Try such:
BindingSource bs = new BindingSource();

C#
<pre lang="c#">
....Event
bs.DataSource = BLL.Cards.GetListCards();
bs.Filter = "yourColumnName like '%" + textBox1.Text + "%'";
ListCards.DataSource = bs;
Posted
Comments
[no name] 16-Apr-13 17:16pm    
Example:

// Create a BindingSource and set its DataSource property to
// the DataView.
BindingSource source1 = new BindingSource();
source1.DataSource = view1;

// Set the data source for the DataGridView.
datagridview1.DataSource = source1;
I must change view1 to BLL.Cards.GetListCards();?



//The Filter string can include Boolean expressions.
source1.Filter = "artist = 'Dave Matthews' OR cd = 'Tigerlily'";

 
Share this answer
 
Comments
[no name] 17-Apr-13 2:30am    
I reed it but question left up
[no name] 17-Apr-13 2:51am    
I tried such, but does not filter:
ListCards.DataSource = list;
ListCards.Columns["StartDay"].Visible = false;
ListCards.Columns["EndDay"].Visible = false;

BindingSource bn = new BindingSource();
bn.DataSource = ListCards.DataSource;
//bn.Filter = "IdUser = " + textBox1.Text + "";
bn.Filter = "Username like '%" + textBox1.Text + "%'";
ListCards.DataSource = bn;
Dilan Shaminda 17-Apr-13 2:50am    
did you try do it? i mean did you try coding ?
[no name] 17-Apr-13 2:54am    
I have DataSource not a DataTable, i have my own type List
So, i made:
XML
BindingList<Cards.Model.Cards> filtered = new BindingList<Cards.Model.Cards>(list.Where(
                                 p => p.Username.Contains(""+textBox1.Text+"")).ToList());
            ListCards.DataSource = filtered;
 
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