如何在 .net 3.5 中禁用列表视图控件中的项目 [英] How do you disable an item in listview control in .net 3.5

查看:29
本文介绍了如何在 .net 3.5 中禁用列表视图控件中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .net 3.5 windows 窗体中,我有一个带有CheckBoxes"= true 的列表视图.是否可以将某些项目变暗或禁用以防止用户选中该框?

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?

推荐答案

您可以使用 ListBoxItem.ForeColor 和 UseItemStyleForSubItems 属性使项目看起来变暗.使用 SystemColors.GrayText 为禁用项目选择主题颜色.避免禁用选择,它会阻止用户使用键盘.仅禁用复选框检查.例如:

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;
    }

这篇关于如何在 .net 3.5 中禁用列表视图控件中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆