Question The Mystery of the Disappearing Combobox

MelancholischMir

New member
Joined
Oct 9, 2014
Messages
3
Programming Experience
10+
Greetings fellow coders,

I am using Visual Studio 2010, .NET Framework 4

I have run into a very unique situation involving the dynamic creation of comboboxes and checkboxes and adding them to my custom "simulated" Control-embedding listview. You see, I am adding the custom listview into a panel and the panel serves as the parent object that will enable scrolling up and down the list after more than 19 items have been added. Using the panel for scrolling was an implementation decision that I decided to use because enabling scrollbars of the listview itself causes wonkiness (the positions of the dynamically-created controls are fixed therefore scrolling down does not cause the controls below view to appear).

Anyway, it turns out that, some time after the scrollbar appears in the panel (after more than 19 items have been added), the VERY first combobox (listView.Controls[0]) "disappears."

eyLl3b8.jpg

What I mean by "disappear" is, the properties Top and Left get set to 0 and the Width gets set to 65535 (sometimes gets set to 0; sporadic behavior there; perhaps suggesting carryover flag of Width's datatype but making no assumptions).

SHBmeHG.jpg

The program never seems to be consistent about when it makes the first combobox disappear, aside from the fact that it is always after 19 list items have been added (thus enabling the scrollbar). Debugging through the code, I change the values back to normal and then it reappears...

iLNM75h.jpg

...but then after adding even more items to the listview, the first combobox disappears again. :( This only happens to fieldView.Controls[0]. Never any of the checkboxes nor subsequent comboboxes. Just that one.

This is completely mysterious behavior, and I was wondering if someone could help me discover the cause.

Here is my source code (C-Sharp project files):
Form code: C++ code - 29 lines - codepad
Custom tab page code (TabPageIncludes.cs): C++ code - 62 lines - codepad
Custom list view code (ControlListView.cs): C++ code - 131 lines - codepad

Much appreciation to any help.
 
Last edited:
I'm curious as to why you would create such a control in the first place when you could use a DataGridView. One of the strengths of a DataGridView is that it never actually displays a child control unless you're editing a cell, so never more than one at a time. Even if you can get your control to work, having loads of child controls is going to affect performance.
 
Good point. Perhaps this is a brainfart on my part. Just something I whipped up in 10 minutes. Was an interesting scenario nonetheless. Still have no idea what happened but guess I'm going with the DataGridView now. Thanks for the reply.
 
Good point. Perhaps this is a brainfart on my part. Just something I whipped up in 10 minutes. Was an interesting scenario nonetheless. Still have no idea what happened but guess I'm going with the DataGridView now. Thanks for the reply.

Some things can be good learning experiences, even if they're not practical in the real world. I've seen custom ListViews that support embedding controls before and they may be useful in situations where you need ListView-specific features, i.e. multiple views and grouping, but they usually only include a small number of controls. A large number of child controls scrolling would almost certainly cause lag I would expect. The DataGridView provides a great deal of flexibility can can support all sorts of custom columns too, so I'd think that that would be your most flexible and practical real-world option.
 
Back
Top Bottom