Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,

I have a combobox that contains column names from a database.
He're the code that gets it:
C#
private void SelectColumn()
       {
           const string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=EmployeeInformation.accdb";
           var conn = new OleDbConnection(connstr);
           conn.Open();
           const string SQL = "SELECT * FROM Employees";
           var cmd = new OleDbCommand(SQL, conn);

           OleDbDataReader reader = cmd.ExecuteReader();
           if (reader != null)
           {
               for (int i = 0; i < reader.FieldCount; i++)
               {
                   cboSearchType.Items.Add(reader.GetName(i));
               }
           }
       }


What I want to do is hide the first row in the combobox so it can not be selected.

How would I do this???

would this be something to change in the query or in the code?

Any help would be greatly appreciated

From,
NattyMan0007
Posted

C#
for (int i = 0; i < reader.FieldCount; i++)
                {
                    cboSearchType.Items.Add(reader.GetName(i));
                }


replace into

C#
for (int i = 0; i < reader.FieldCount; i++)
                {
                    if(i!=0)//specify which row you want hide eg:i=0
                      {
                         cboSearchType.Items.Add(reader.GetName(i));
                      }
                }
 
Share this answer
 
v2
Fixed it by changing the query to exclude the columns that I don't want
 
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