lock checkbox in Listview
Hi
How can I to lock checkbox in listview, for to user, The user can run in scrollbar, but he can not to check or uncheck when frame3 is disabed.
I tried code below
Code:
Private Sub lvwGrupoProduto_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Frame3.Enabled = False Then
If Item.Checked = True Then
Item.Checked = False
Else
Item.Checked = True
End If
End If
End Sub
But when I read data from table I want to check using code, I thought in to use before read code from table put
Code:
frame.enabled = true
Is there other way ?
Re: lock checkbox in Listview
Code:
'~~> Adding Sample Data to Listview
Private Sub Form_Load()
Dim column_header As ColumnHeader, list_item As ListItem
'~~> Create the column headers.
Set column_header = ListView1.ColumnHeaders.Add(, , "Number", 1000)
'~~> Start with report view.
ListView1.View = lvwReport
ListView1.Checkboxes = True
Set list_item = ListView1.ListItems.Add(, , "123")
Set list_item = ListView1.ListItems.Add(, , "456")
Set list_item = ListView1.ListItems.Add(, , "850")
Set list_item = ListView1.ListItems.Add(, , "801")
For i = 1 To ListView1.ListItems.Count
'~~> Set Tag Property
ListView1.ListItems(i).Tag = "L"
Next
End Sub
'~~> Preventing Checking/Unchecking
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Item.Tag = "L" Then Item.Checked = False
End Sub
Re: lock checkbox in Listview
mutley,
Your code will do not allow Checking/Unchecking when Frame3 is disabled.
And also, when you check/uncheck the item via code, it is possible even if the Frame3 is disabled.
For example:
Code:
Option Explicit
Private Sub Form_Load()
'~~~ Sample data
Dim i As Long
For i = 1 To 10
ListView1.ListItems.Add , , i
Next
'~~~ We are disabling Frame3 for testing. After form loads, click "Command2" to see the effect.
Frame3.Enabled = False
End Sub
'~~~ Your actual code, which works fine.
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Frame3.Enabled = False Then
If Item.Checked = True Then
Item.Checked = False
Else
Item.Checked = True
End If
End If
End Sub
Private Sub Command1_Click() '~~~ This button will enable/disable Frame3
Frame3.Enabled = Not Frame3.Enabled
End Sub
Private Sub Command2_Click() '~~~ This button will check an item(item number 2). Click this button after Form loads. ie, when Frame3 is disabled.
ListView1.ListItems(2).Checked = True
End Sub
So, I think your code is perfect for what you are asking. If I interpret your question in the wrong way, please make it clear...:wave:
Re: lock checkbox in Listview
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Frame3.Enabled = False Then
Item.checked = not Item.checked
End If
End Sub
Would be a concise way of doing it.
Re: lock checkbox in Listview
Quote:
Originally Posted by
Lee Chetwynd
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Frame3.Enabled = False Then
Item.checked = not Item.checked
End If
End Sub
Would be a concise way of doing it.
Sir, I am using the following code for loading the status of Checkbox;
Code:
If (.Fields("LPrint") = True) Then
ListView1.ListItems(k).Checked = True
'ListView1.SelectedItem.Selected = False
ListView1.ListItems(k).Tag = "L"
Else
ListView1.ListItems(k).Checked = False
End If
In next load, the particular checkbox should be disabled. So i am using the following code.
Code:
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
If Item.Tag = "L" Then Item.Checked = False
End Sub
But Nothing happened. still i can check and uncheck the specific checkbox.
My Actual need is ;
I have a listview that is being populated via a database. The first time i have to check the checkbox and value will be updated. When next loading, the listview checkbox is also checked based on the status of a database field. But it should be disabled. The user will focus next checkbox only. Please help me.
Thanks