A
A
Anton2016-03-09 18:54:52
C++ / C#
Anton, 2016-03-09 18:54:52

How to fix autocomplete combobox?

I made an auto completion of the list, but the problem is that the window can be stretched when displaying the results. Is there any way to customize what would look like a normal option from the list?
uq4MBTGhwww.jpg
All values ​​are taken from the database
UPD: added code, maybe needed

private void fillComboBox()
        {
            String connectionString = "Data Source=(LocalDB)\\v11.0;AttachDbFilename='|DataDirectory|Database.mdf';Integrated Security=True;";
            String sql = "SELECT * FROM CPOSITION";
            SqlDataAdapter adapter = new SqlDataAdapter();
            IList<string> lstPosition = new List<string>();
            try
            {
                using(SqlConnection con = new SqlConnection(connectionString))
                {
                    con.Open();
                    SqlCommand command = new SqlCommand(sql,con);
                    adapter.SelectCommand = command;
                    DataTable dt = new DataTable();
                    adapter.Fill(dt);
                    adapter.Dispose();
                    command.Dispose();
                    con.Dispose();
                    foreach (DataRow row in dt.Rows)
                    {
                        lstPosition.Add(row.Field<string>("position"));
                    }
                    this.comboBox1.Items.AddRange(lstPosition.ToArray<string>());
                    this.comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
                    this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;


                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey S., 2016-03-10
@Winsik

set the resize property

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question