|
-
Jun 29th, 2010, 08:47 AM
#1
Thread Starter
Fanatic Member
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 ?
-
Jun 29th, 2010, 09:06 AM
#2
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 29th, 2010, 11:20 AM
#3
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...
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Aug 20th, 2013, 03:43 AM
#4
New Member
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.
-
Apr 27th, 2023, 02:41 AM
#5
Lively Member
Re: lock checkbox in Listview
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|