在vb.net中禁用ListView项目 [英] Disable listview item in vb.net

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

问题描述

我试图在列表视图中禁用项目(行),但似乎没有.enable = false之类的选项,并且我试图找到任何东西来通过禁用使我的项目变为可见的.有没有类似的东西?如果允许用户选择它,则该项目已启用,否则它是可见的,但未启用.

I am trying to disable item (row) in my list view but its seem there no option like .enable = false and I tried to find anything to get my item to by disable but visible. Is there anything like that? If the user is allowed to select it then the item is enabled else it's visible but not enabled.

我在数据库中有一个表,管理员将在其中填充该表,用户可以在其中查看该窗口或不查看该窗口,因此我希望用户能够看到它,如果不允许查看,则将其禁用.

I have a table in the database that admin will fill it in which the user can view the window or not, so I want the user to able to see it and if not allowed to view it then its disable.

推荐答案

仅当MultiSelect设置为False并且为每个项目都设置了.Tag属性时,此方法才有效. (是或否).

This only works if MultiSelect is set to False and the .Tag property is set for every item. (Yes or No).

Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        If Not ListView1.SelectedItems.Count = 0 Then
            Dim item As ListViewItem = ListView1.SelectedItems(0)
            If item.Tag.ToString = "No" Then
                item.Selected = False
            End If
        End If
End Sub

按照@ jmcilhinney,以下代码应与MultiSelect = True一起使用.我试图访问添加到集合中的最后一个项目,但是似乎SelectedItems集合的排序与项目在ListView中出现的顺序相同;与预期不同的是,最后添加的项目将在集合中位于最后.

As per @ jmcilhinney , The following code should work with MultiSelect = True. I tried to access the last item added to the collection but it seems that the SelectedItems collection is ordered the same as the order the items appear in the ListView; not as expected the last item added would be last in the collection..

Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        If Not ListView1.SelectedItems.Count = 0 Then
            For Each item As ListViewItem In ListView1.SelectedItems
                If item.Tag.ToString = "No" Then
                    item.Selected = False
                End If
            Next
        End If
End Sub

这篇关于在vb.net中禁用ListView项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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