I have a problem 🙂 I try to make a quick search with highlighting in a datagridview.
In my datagridview is an excel sheet.
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\test2.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "TestTable");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
dataGridView1.DataSource = DtSet.Tables[0];
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
And I need it like this:

I have no idea, I hope someone can help me 🙂
Thank you very mutch
1 – Load from excel to datatable ( which you already did it) then save DataTable to global Variable
2- When search clicked use DataTable.Select : example or since you are using oledb you can again select your excel with a simple query instead of Datatable select, up to you, you might give it a try if datatable select’s performance is poor. Example excel searching
3- then Highlight your text in datagrid, i havent used windows forms such a long time , but maybe http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/43f6b81f-4cb7-4e8e-bd29-e3645f200734/ might be a clue for you
Ok I used links i provided so far so good, except highliht everything work:
A Simple Helper class for reading excel and searching in DataTable:
Hope this helps.