Hello,
I filled up a DataGridView from a csv file using the code as follow:
Everything works and at the start I can see my DataGridView correctly filled up by datas from csv file.
The problem is that I am not able to filter the rows by textbox or sort the column by clicking on header word.
I tried differents ways by reading solution on the web but nothings works...
can anyone suggest me some solution for this pls?
I have an identical database .mdf, in this case I added a DataSets to my c# project and I fill up my DataGridView just by setting the ClientsTableBindingSouce as source of data
In this case I am able to sort and filter very easly the rows of the datagridview at runtime just by typing text in a textbox.
I filled up a DataGridView from a csv file using the code as follow:
Everything works and at the start I can see my DataGridView correctly filled up by datas from csv file.
The problem is that I am not able to filter the rows by textbox or sort the column by clicking on header word.
I tried differents ways by reading solution on the web but nothings works...
can anyone suggest me some solution for this pls?
C#:
private void LoadDatabaseBtn_Click(object sender, EventArgs e)
{
string filecsv = @"D:\Database.csv";
DGV.DataSource = LoadCSV(filecsv);
DGV.Refresh();
}
public List<Client> LoadCSV(string csvfile)
{
var query = from l in File.ReadAllLines(csvfile)
let data = l.Split(',')
select new Client
{
name= data[0],
id = data[1],
tel = data[2],
addr = data[3],
city = data[4],
};
return query.ToList();
}
}
public class Client
{
public string name { get; set; }
public string id { get; set; }
public string tel { get; set; }
public string addr { get; set; }
public string city { get; set; }
}
I have an identical database .mdf, in this case I added a DataSets to my c# project and I fill up my DataGridView just by setting the ClientsTableBindingSouce as source of data
In this case I am able to sort and filter very easly the rows of the datagridview at runtime just by typing text in a textbox.
C#:
private void filternameTxt_TextChanged(object sender, EventArgs e)
{
ClientsTableBindingSource.Filter = string.Format("name LIKE '%{0}%'", filternameTxt_Text);
DGV.Refresh();
}