Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I am trying to bind the value that is coming in list object to Listbox but on debug it is showing value but when form loads listbox is empty. I am trying to create a IE BHO in which i want to load all the words that are available in excelsheet file name DictionaryFile. Below is my code:

Please help me out, thanking you all

private void Form1_Load(object sender, EventArgs e)
          // provider = (CodeDomProvider)Activator.CreateInstance("Microsoft.JScript", "Microsoft.JScript.JScriptCodeProvider").Unwrap();
           if (istrue == false)

       private void LoadAllWord()
           istrue = true;
           OleDbConnection objConn = null;
           //Passing Query String and Ole connection object to Ole DB Command
           OleDbCommand cmd = new OleDbCommand();
           //Declaring OleDbDataAdapter object which execute the OleDbCommand in next line.
           OleDbDataAdapter oleda = new OleDbDataAdapter();
           //Creating Query String
           string querystr = "";
           //Declaring new Data table with dt object
           DataTable dt = new DataTable();
           DataSet ds = new DataSet();

               string FileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86) + "\\Dictionary\\Dictionary.xls";
               //Creating Connection String
               String connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + FileName + " ;Persist Security Info=False;Extended Properties=Excel 8.0;";
               //Passing Connection String Value into Ole Connection Object
               objConn = new OleDbConnection(connString);
               //Connection is getting open from here
               //Creating Query String
              // querystr = @"SELECT *  from [DictionaryFile$] where CHECK_DIGIT > 0";// Record_Level < 501 and
               querystr = @"SELECT *  from [DictionaryFile$]";// Record_Level < 501 and
               //Passing Query String and Ole connection object to Ole DB Command
               cmd = new OleDbCommand(querystr, objConn);
               //Passing Command Value to OldDbDataAdapter object
               oleda.SelectCommand = cmd;
               // Filling OleDataAdapter value in DataTable Object dt

               List<string> lst = new List<string>();
               foreach (DataRow r in dt.Rows)

              // lstInstalledWord.Items.Clear();
               //lstInstalledWord.DisplayMember = "words";
               //lstInstalledWord.ValueMember = "words";
               //lstInstalledWord.DataSource = lst;
               //lstInstalledWord.DisplayMember = "words";
               //lstInstalledWord.DataSource = ds.Tables["words"];

           catch (Exception ex)

           //lstInstalledWord.DataSource = dt;//DataSource to GrigView(Id:gvOne)

1 solution

Based on few comments words (querystring, gridview, etc), I assume you are working on a web application and it's an ASP.NET app code.

If so, you need to bind the items once defined to the list.
Post fetching the values, do:
oleda.SelectCommand = cmd;
lstInstalledWord.DataSource = dt;
lstInstalledWord.DisplayMember = "words";
lstInstalledWord.ValueMember = "words";

Once you define the datasource, you need to bind too. Try!
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