开发者

Controlling the order of controls being populated on a form in VB 2008

开发者 https://www.devze.com 2023-03-23 13:49 出处:网络
My form contains a datagrid and a checked listbox. The listbox is populated on the form_load event. There\'s a function called when the datagrid\'s SelectionChanged event is triggered that modifies th

My form contains a datagrid and a checked listbox. The listbox is populated on the form_load event. There's a function called when the datagrid's SelectionChanged event is triggered that modifies the checkmarks in the listbox. It all works fine when I manually click on any item in the datagrid.

However, the very first time the form runs, the checkmarks are not affected, even though the first item in the 开发者_运维技巧datagrid appears selected. I discovered that this is because the actual listbox is not yet populated on the form at the time the very first SelectionChanged event is triggered. So when the function tries setting the checkboxes, it doesn't get anywhere, since it doesn't see any items in the listbox.

Somehow the datagrid is getting populated, even before the form_load event is triggered. I need the listbox to be populated before the datagrid is populated, but I have no idea how to control this.

Any ideas how to solve my dilemma?

Thanks.


This doesn't answer your question directly, but perhaps after you load the list box you can call the SelectionChanged sub in order to cause the behavior you want. Rather than try to control the order.


I solve these problems (do something during formload, but after all controls were loaded) by using a timer. it's disabled, with a time of 10 ms. in formload as last action I enable it. in the timer tick I disable the timer and execute the rest of the code.

So the timertick executes immediatly after the form has loaded.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号