简体   繁体   中英

comboBox1.Items.Add ..Collection?

I have a textbox with a auto complete and i want to take its collection and populate a comboBoxs items?

I would like to have my comboBoxs items be the collection, at the moment in my drop down it just says (Collection) so how do i populate it with the collection not just the word.

comboBox1.Items.Add(DatabaseService.Instance.AutoComplete("AuditIT", "AutoComplete", paramListAutoCom));

This is the method i populate the collection with:

public AutoCompleteStringCollection AutoComplete(string dataBase, string procedure, SqlParameter[] parameters)
            {
                try
                {
                   String SearchAt = parameters[2].Value.ToString();
                    if (dataBase.Length > 0) { procedure = dataBase + ".." + procedure; } //Set procedure to DBNAME..ProcedureName
                    AutoCompleteStringCollection namesCollection =
                  new AutoCompleteStringCollection();

                    SqlDataReader dReader;
                    SqlCommand cmd = new SqlCommand(procedure, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    foreach (SqlParameter p in parameters)
                    {
                        if (p != null)
                        {
                            cmd.Parameters.Add(p);
                        }
                    }
                    con.Open();
                    dReader = cmd.ExecuteReader();
                    if (dReader.HasRows == true)
                    {
                        while (dReader.Read())
                            //namesCollection.Add(dReader["SystemUser"].ToString());
                            namesCollection.Add(dReader[SearchAt].ToString());
                    }
                    con.Close();
                    dReader.Close();
                    return namesCollection;
                }
                catch (Exception ex)
                {

                    MessageBox.Show("" + ex);
                    return null;
                }
            }

Please let me know if you need anything else.

Thanks in advance.

AutoCompleteStringCollection Collection = DatabaseService.Instance.AutoComplete("AuditIT", "AutoComplete", paramListAutoCom);
           foreach (String Item in Collection)
           {
               comboBox1.Items.Add(Item);
           }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM