隐藏组合框C#中的某一行 [英] Hide certain row from combobox C#

查看:78
本文介绍了隐藏组合框C#中的某一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个包含数据库列名的组合框。

他是获得它的代码:

Hi,

I have a combobox that contains column names from a database.
He're the code that gets it:

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));
               }
           }
       }





我想做的是隐藏组合框中的第一行无法选择。



我该怎么办?



这会在查询或代码中改变吗?



任何帮助将不胜感激



来自,

NattyMan0007



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

推荐答案

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





替换为





replace into

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));
                      }
                }


通过更改查询以排除我不想要的列来修复它
Fixed it by changing the query to exclude the columns that I don't want


这篇关于隐藏组合框C#中的某一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆