简体   繁体   中英

C# ComboBox in DataGridView loads datasource only when clicked(when it's cell is in edit mode)

I have a DataGridView that includes a ComboBoxColumn. I am supposed to put a large dataset (about 20000 items) into the comboboxes to select from, so that the user can enter the first few digits and then click the correct number.

The problem with large comboboxes is that they take a long time to load. Now, this wouldn't be a problem with normal comboboxes (well, it would make the initial load time of the program larger); but with comboboxes inside a datagridview it is: a combobox inside a DGV only loads as soon as it's cell is in edit mode, so it seems. As soon as I click out of the cell, the combobox "unloads", ie if I click it again, I have to wait for it to load again.

Is there a way around this or maybe a way to load those 20k entries faster?

I don't think this needs a code example, as it's not really about the code itself but rather a behavior of winforms.

EDIT: We decided to make it a textbox and just check whether the value is in the list of allowed items or not

I think as long as you use that high count of entries it always be slow. You can try loading it into your RAM (eg public List<YourClass> tmpList {get;set; ) and connect your Combobox with the list instead of the binding source. That would reduce queries or reloads, as long as there hasn't been an Update to your entries.

Another way to reduce these entries is to try to find another way to do so. Do you need that much of values or is there another way to determine the correct data? Maybe overthink the workflow of this grid or the values.

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