Vb.net 需要从OwnerDrawn ListView中删除复选框,但仍保留复选框功能

Vb.net 需要从OwnerDrawn ListView中删除复选框,但仍保留复选框功能,vb.net,listview,checkbox,ownerdrawn,Vb.net,Listview,Checkbox,Ownerdrawn,我有一个定制的listview控件,它向用户显示通知列表。基本上,当收到新通知时,会向listview中添加一个粗体的新条目。当用户阅读通知时,它将转换为常规字体 我能找到的唯一方法是使用复选框来实现这一可能是读取状态。因此,新通知将检查其项,并且在读取时取消选中。这工作得很好,似乎达到了我的需要 然而,我的问题是……有没有一种方法可以删除复选框的图形,但仍将功能保留在后台。例如,不为listview项绘制复选框,但仍然能够使用listview.checkbox=True和ListViewIte

我有一个定制的listview控件,它向用户显示通知列表。基本上,当收到新通知时,会向listview中添加一个粗体的新条目。当用户阅读通知时,它将转换为常规字体

我能找到的唯一方法是使用复选框来实现这一可能是读取状态。因此,新通知将检查其项,并且在读取时取消选中。这工作得很好,似乎达到了我的需要

然而,我的问题是……有没有一种方法可以删除复选框的图形,但仍将功能保留在后台。例如,不为listview项绘制复选框,但仍然能够使用listview.checkbox=True和ListViewItem.Checked=True

我的ListView控件是ownerdrawn,我的DrawItem事件的代码如下所示:

Protected Overrides Sub OnDrawItem(e As DrawListViewItemEventArgs)
    Try
        If Not (e.State And ListViewItemStates.Selected) = 0 Then
            'Draw the background for a selected item.
            e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Highlight, e.Bounds)
            e.DrawFocusRectangle()
        Else
            'Draw the background for an unselected item.
            e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds)
        End If

        e.DrawBackground()
        e.DrawDefault = True
        MyBase.OnDrawItem(e)

    Catch ex As Exception
        MsgBox("Exception Error: " & ex.Message, MsgBoxStyle.Critical, "Module: lsvOverdueCalls_DrawItem()")
    End Try
End Sub
如果我删除e.DrawDefault=True,它将删除复选框,但是我无法控制新通知的粗体字体

谢谢你的帮助。
谢谢

我通过创建一个新的ListViewItem类来解决这个问题,该类继承ListViewItem,然后添加一个自定义属性。然后,我在整个代码中使用新类引用ListViewItem,这允许我向默认ListViewItem添加一个新属性

Public Class cust_ListViewItem
    Inherits ListViewItem

    Private _read As Boolean
    Private RegularFont As New Font(Me.Font.FontFamily, Me.Font.size, FontStyle.Regular)
    Private BoldFont As New Font(Me.Font.FontFamily, Me.Font.size, FontStyle.Bold)

    Public Property Read As Boolean
        Get
            Return _read
        End Get
        Set(value As Boolean)
            _read = value
            MarkAsRead()
        End Set
    End Property

    Private Sub MarkAsRead()
        If _read Then Me.Font = RegularFont Else Me.Font = BoldFont
    End Sub
End Class
然后,为了调用我的新属性,我使用了以下命令:

    Dim lvi As cust_ListViewItem = New cust_ListViewItem
    If Notifications(x).Read = True Then
    lvi.Read = True
    ...

但是,我还发现了以下内容,它允许您从各个listview项目中完全删除复选框,这正是我最初试图实现的。我刚刚将代码添加到自定义listview类中,并将代码应用到每个listview项。

为什么不定义自己的自定义类来继承ListViewItem?然后,您可以将该类的实例添加到ListView,而不是标准的ListViewItem对象?然后你可以添加任何你想要的功能。@jmchiliney这是我已经做过的。这是我的自定义类,我不知道如何从中删除复选框。如果没有复选框,如何检查复选框,以及用户如何知道什么是选中的还是未选中的?如果您有一个表示读取或新状态的布尔子项,则可以根据该子项加粗或不加粗。如果没有列标题,则该项不会显示给用户。这是您自己的类。只需添加一个布尔属性。好的,谢谢您的建议。只是一个问题,我如何向类中添加仅影响ListViewItems的自定义属性?例如,如果我想添加一个读取属性,比如ListViewItem.Read=True?我知道如何添加影响整个ListView的属性,但不影响项目。谢谢