禁用选择列表框中的某些项目? [英] Disable selecting certain items in listbox?

查看:46
本文介绍了禁用选择列表框中的某些项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多选列表框,我需要禁止用户选择列表框中的某些项目.我尝试查看列表框启用,但这似乎仅适用于整个列表框.有任何想法吗?这是我的列表框,目前我正在遍历该项目,以希望禁用该项目:

I have an multiselect listbox that i need to disable users from selecting certain items in the listbox. I've tried looking at the listbox enable but that seems to be for the whole listbox only. Any ideas? Here's my listbox, i currently is looping through the item hoping to disable the item:

Dim lItem As Long
For lItem = 0 To Sheet1.ListBox1.ListCount - 1
    If Sheet1.ListBox1.Selected(lItem) Then
        Sheet1.ListBox1.Enabled(lItem) = False ' don't work?
    End If
Next

推荐答案

For it = 0 To Sheet1.ListBox1.ListIndex 

  If Sheet1.ListBox1.Selected(it) Then
     Sheet1.ListBox1.Selected(it) = False 
     Sheet1.ListBox1.RemoveItem (it)   
  End If

Next

第1行:遍历列表框的所有索引

Line1 : goes through all the indexes of the listbox

第2行:找到选中的项目

Line2 : find the selected item

第3行:取消选择

第4行:删除所选的项目

Line4 : removes the item selected

这篇关于禁用选择列表框中的某些项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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