在 VB 2008 中控制窗体上控件的填充顺序
我的表单包含一个数据网格和一个选中的列表框。列表框在 form_load 事件上填充。当数据网格的 SelectionChanged 事件被触发时,会调用一个函数来修改列表框中的复选标记。当我手动单击数据网格中的任何项目时,一切正常。
但是,表单第一次运行时,即使数据网格中的第一项显示为选中状态,复选标记也不会受到影响。我发现这是因为在触发第一个 SelectionChanged 事件时,实际的列表框尚未填充到表单上。因此,当该函数尝试设置复选框时,它不会到达任何地方,因为它在列表框中看不到任何项目。
不知何故,即使在触发 form_load 事件之前,数据网格也会被填充。我需要在填充数据网格之前填充列表框,但我不知道如何控制它。
有什么想法可以解决我的困境吗?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不能直接回答您的问题,但也许在加载列表框后您可以调用 SelectionChanged 子函数以引起您想要的行为。而不是试图控制顺序。
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.
我通过使用计时器解决了这些问题(在表单加载期间执行某些操作,但在加载所有控件之后)。
它被禁用,时间为 10 毫秒。
在 formload 中,作为最后一个操作,我启用了它。
在计时器刻度中,我禁用计时器并执行其余的代码。
因此,计时器在表单加载后立即执行。
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.