What's the fastest way to populate a combo box in C #?

What is the fastest way to populate a ComboBox in C #?

  • FROM Add()

  • Bind ComboBox to dataset

Or is there a faster way?

Thank.

-2


source to share


3 answers


You will probably find that the fastest way to do this would be to read the DB from the datareader and then call .Add () in a loop, but using the numeric indexed DataReader fields (instead of named properties).



+2


source


Well, using data binding is a lot less code for anything other than one element:

myComboBox.DataSource = myDataSet; myComboBox.DataBind ();



Of course, this assumes that your DataSet already contains data. Perhaps you can clarify your question?

0


source


Your fastest way will probably either bind to the DataReader , or iterate over the DataReader and use a method Add()

for the ComboBox. Anyway, the key is not whether you are binding or iterating (I haven't used these tools and therefore can't tell you which is faster), the key is using the DataReader.

Using a DataSet, you are loading and populating a rather heavy data object. If you notice speed issues, this is probably the culprit. Just switching to DataReader (using Add()

or binding) will probably give you a boost.

Of course, all of this assumes that you see the speed issue in the first place. If you don’t, and no one is complaining about the speed of your application, and your application does not have predicted growth, which could cause a problem, then stay on your current path! "Premature optimization is the root of all evil."

0


source







All Articles