listview and checkbox

User avatar
sal21
PlatinumLounger
Posts: 4470
Joined: 26 Apr 2010, 17:36

listview and checkbox

Post by sal21 »

i'm on vb 6.0

I need to permit to the user to check only a checkbox,"one by one", and not permit to use a multiselect checkbox, possible?

Similar oprtion button.

User avatar
HansV
Administrator
Posts: 79287
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: listview and checkbox

Post by HansV »

Create an event procedure for the ItemCheck event of the listview:

Code: Select all

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    Static LastChecked As ListItem
    If Item.Checked Then
        If Not LastChecked Is Nothing Then
            LastChecked.Checked = False
        End If
        Set LastChecked = Item
    End If
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4470
Joined: 26 Apr 2010, 17:36

Re: listview and checkbox

Post by sal21 »

HansV wrote:Create an event procedure for the ItemCheck event of the listview:

Code: Select all

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    Static LastChecked As ListItem
    If Item.Checked Then
        If Not LastChecked Is Nothing Then
            LastChecked.Checked = False
        End If
        Set LastChecked = Item
    End If
End Sub
I have no words!!!!

Work perfect!
Tks bro

User avatar
sal21
PlatinumLounger
Posts: 4470
Joined: 26 Apr 2010, 17:36

Re: listview and checkbox

Post by sal21 »

HansV wrote:
22 Mar 2020, 16:39
Create an event procedure for the ItemCheck event of the listview:

Code: Select all

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    Static LastChecked As ListItem
    If Item.Checked Then
        If Not LastChecked Is Nothing Then
            LastChecked.Checked = False
        End If
        Set LastChecked = Item
    End If
End Sub
HI BRO, sorry if i replay on old post.

actually i use this code to check un check a checkbox in msflexgrid:

Code: Select all


Private Sub MSFlexGrid1_Click()
    
    With MSFlexGrid1

        If .Col = 0 And .Row >= 1 Then
        
            If .CellPicture = picChecked Then
                Set .CellPicture = picUnchecked
            Else
                Set .CellPicture = picChecked
            End If

        End If

    End With
    
End Sub
possible to have the same condition in msflexgrid...?

In effect i need to maintain in live the last checked cell.

User avatar
HansV
Administrator
Posts: 79287
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: listview and checkbox

Post by HansV »

I cannot test - does this work?

Code: Select all

Private Sub MSFlexGrid1_Click()
    Static OldRow As Long, OldCol As Long
    Static NewRow As Long, NewCol As Long
    With MSFlexGrid1
        NewRow = .Row
        NewCol = .Col
        If NewCol = 0 And NewRow >= 1 Then
            If Not .CellPicture = picChecked Then
                Set .CellPicture = picChecked
                If OldCol = 0 And OldRow >= 1 Then
                    .Row = OldRow
                    .Col = OldCol
                    Set .CellPicture = picUnchecked
                    .Row = NewRow
                    .Col = NewCol
                End If
                OldRow = NewRow
                OldCol = NewCol
            End If
        End If
    End With
End Sub
There may be better ways...
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4470
Joined: 26 Apr 2010, 17:36

Re: listview and checkbox

Post by sal21 »

HansV wrote:
08 Aug 2024, 10:32
I cannot test - does this work?

Code: Select all

Private Sub MSFlexGrid1_Click()
    Static OldRow As Long, OldCol As Long
    Static NewRow As Long, NewCol As Long
    With MSFlexGrid1
        NewRow = .Row
        NewCol = .Col
        If NewCol = 0 And NewRow >= 1 Then
            If Not .CellPicture = picChecked Then
                Set .CellPicture = picChecked
                If OldCol = 0 And OldRow >= 1 Then
                    .Row = OldRow
                    .Col = OldCol
                    Set .CellPicture = picUnchecked
                    .Row = NewRow
                    .Col = NewCol
                End If
                OldRow = NewRow
                OldCol = NewCol
            End If
        End If
    End With
End Sub
There may be better ways...
great! Work!
Tks