Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6073673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:17:49+00:00 2026-05-23T10:17:49+00:00

I have a problem :-) I try to make a quick search with highlighting

  • 0

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:

enter image description here

I have no idea, I hope someone can help me 🙂

Thank you very mutch

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:17:50+00:00Added an answer on May 23, 2026 at 10:17 am

    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:

    public class ExcelHelper
        {
            public static DataTable LoadXLS(string strFile, String sheetName)
            {
                DataTable dtXLS = new DataTable(sheetName);
                try
                {
                    string strConnectionString = "";
                    if (strFile.Trim().EndsWith(".xlsx"))
                    {
                        strConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", strFile);
                    }
                    else if (strFile.Trim().EndsWith(".xls"))
                    {
                        strConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";", strFile);
                    }
                    OleDbConnection SQLConn = new OleDbConnection(strConnectionString);
                    SQLConn.Open();
                    OleDbDataAdapter SQLAdapter = new OleDbDataAdapter();
                    string sql = "SELECT * FROM [" + sheetName + "$] "; // "WHERE " + column + " = " + value;
                    OleDbCommand selectCMD = new OleDbCommand(sql, SQLConn);
                    SQLAdapter.SelectCommand = selectCMD;
    
                    SQLAdapter.Fill(dtXLS);
                    SQLConn.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
    
                return dtXLS;
            }
    
            public  static DataTable QueryDataTable(DataTable dt, string column,string value)
            {
                var drs =  dt.Select(String.Format("{0} LIKE '%{1}%'", column, value));
                DataTable dt2 = dt.Clone();
                foreach (var dataRow in drs)
                {
                    dt2.ImportRow(dataRow);
                }
                return dt2;
            }
        }
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with base classes in WPF. I try to make a base
I have problem when I try insert some data to Informix TEXT column via
I have a problem using the SSIS. I try to import data from database
I have a big problem dealing with data I try to download in my
i have a problem,,i try to make a table using datatable...i've been download from
I have got a problem when I try to make following simple connections QSpinBox
I have a problem when I try to persist my model. An exception is
I have this problem when i try to synchronize a observable list with listbox/view
I have a problem and I will try to explain the issue: I have
I have some problem's with a simple application in JSF 2.0. I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.