开发者

Winforms ListView ItemCheck on load

开发者 https://www.devze.com 2023-04-12 13:29 出处:网络
I have a winform containing tabs, containing a usercontrol, containing a listview with checkboxes. private void lvwRoles_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)

I have a winform containing tabs, containing a usercontrol, containing a listview with checkboxes.

    private void lvwRoles_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
    {
        if (!m_loading && m_locked)
        {
            e.NewValue = e.CurrentValue;
            return;
        }

The listview is assigned it's items (some is checked) in a method (in the user control) that is called from the parent form. This is done on load of the parent form.

My problem is that the ItemCheck occurs when 开发者_运维百科I click the corresponding tab the first time. That results in the m_loading state variable being false since long ago.

Thus no item is ever checked when the usercontrol is m_locked.

Is there a way to solve this without changing how the listview is populated?


The listview is assigned it's items (some is checked) in a method (in the user control) that is called from the parent form. This is done on load of the parent form.

Even though you call that method in the parent form_load that effectively fires when you select that tab. Set m_loading to false after user control loads, which will not occur until you select that tab.

0

精彩评论

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

关注公众号