Exemple #1
0
        internal void Run()
        {
            if (listbox == null)
            {
                listbox          = new ListBox();
                listbox.Location = new Point(textBoxBase.Location.X, textBoxBase.Location.Y + textBoxBase.Size.Height);
                listbox.Click   += new EventHandler(listBox1_Click);
                listbox.KeyDown += new KeyEventHandler(listbox_KeyDown);
            }
            if (!groupBox1.Contains(listbox))
            {
                groupBox1.Controls.Add(listbox);
                listbox.BringToFront();
            }
            da.SelectCommand = new SqlCommand("SELECT DISTINCT " + textBoxBase.Name.Substring(3) + " FROM " + p + " WHERE " + textBoxBase.Name.Substring(3) + " LIKE \'" + textBoxBase.Text + "%\'", sc);
            ds.Clear();
            listbox.Items.Clear();
            sc.Open();
            da.SelectCommand.ExecuteNonQuery();
            sc.Close();
            da.Fill(ds);


            foreach (DataTable table in ds.Tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    foreach (DataColumn column in table.Columns)
                    {
                        listbox.Items.Add(row[column]);
                    }
                }
            }

            listbox.Height = (listbox.Items.Count + 1) * listbox.ItemHeight;
            if (listbox.Items.Count == 0)
            {
                groupBox1.Controls.Remove(listbox);
            }
        }