質問

i have four comboboxs, i want to fill them with the same data brought from the same table, but this task takes a lot of time on a pocket pc device. So i wonder if there is a way faster than this :

private void autreform_Load(object sender, EventArgs e)
        {

            DataTable dtable = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter("select designation, num_produit from STK_PRODUITS_GENERIQUE where num_famille in (select num_famille from  parametrage_vidange where produit='autres') ", mySqlConnection1);
            adapter.Fill(dtable);

            try
            {
                remplircombo(comboBox1, dtable);
                remplircombo(comboBox2, dtable);
                remplircombo(comboBox3, dtable);
                remplircombo(comboBox4, dtable);
            }
            catch (Exception excr) { MessageBox.Show(excr.Message); }
        }

 private void remplircombo(ComboBox combo, DataTable dtable )
        {
            combo.DataSource = new BindingSource(dtable, null);
            combo.DisplayMember = "designation";
            combo.ValueMember = "num_produit";
        }
役に立ちましたか?

解決

Usually you should not add a lot of items to a combobox; It's slow and it gets hard for users to pick the correct item.

I prefer using an user control to show my data in a friendly way.

If it's not a satisfiable change you could suspend form layout before loading the items into the combobox:

try
{
this.SuspendLayout();
}
finally
{
this.ResumeLayout();
} 

他のヒント

No that's acceptable. However, I would move your logic of querying the DB into a separate class.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top