WinForms ListBox with readonly/disabled items

后端 未结 5 1596
傲寒
傲寒 2021-01-18 20:39

Is there a way to make some of the items in a ListBox readonly/disabled so they can\'t be selected? Or are there any similar controls to ListBox to provide this functionalit

5条回答
  •  感情败类
    2021-01-18 21:34

    To get read-only behaviour I have MyCBLLocked, a boolean associated with the MyCBL checkbox list control, and on the CheckItem event I do:

    private void MyCBL_ItemCheck(object sender, ItemCheckEventArgs e)
    {
        if (MyCBLLocked)
            e.NewValue = e.CurrentValue;
        }
    

    So instead of

    MyCBL.Enabled = false;
    

    I use

    MyCBLLocked = true;
    

    and the user can scroll through the many selections but not mess things up with changes.

提交回复
热议问题