How do you disable an item in listview control in .net 3.5

前端 未结 5 670
渐次进展
渐次进展 2020-11-30 14:13

In .net 3.5 windows forms I have a listview with \"CheckBoxes\" = true. Is it possible to dim out or disable some items to prevent the user from checking the box?

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 14:13

    You can use the ListBoxItem.ForeColor and UseItemStyleForSubItems properties to make the item look dimmed. Use SystemColors.GrayText to pick the theme color for disabled items. Avoid disabling selection, it prevents the user from using the keyboard. Only disable the checkbox checking. For example:

        private void listView1_ItemCheck(object sender, ItemCheckEventArgs e) {
            // Disable checking odd-numbered items
            if (e.Index % 2 == 1) e.NewValue = e.CurrentValue;
        }
    

提交回复
热议问题