How to lock checkbox list view In Vb.net?

Shahab a 261 Reputation points
2022-06-25T16:01:53.95+00:00

Hi all
I have a list View that have 3 rows by Checkbox.
Now how to do lock check box that users can't change it.
Thanks all

Developer technologies VB
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. LesHay 7,141 Reputation points
    2022-06-25T16:21:42.823+00:00

    Hi

    Not sure if you are asking about a CheckedListBox or not. Anyway, this code could be applied to most controls. This is an example project. Start new and put a CheckedListBox1 and a Button 1onto Form1 and try it out. If it is doing what is required then apply it to your own code. Remember, you don't need to do it through a Button Click event, you can just use the one line of code anywhere and it will yoggle the Enabled state of the control each time it is executed.

    ' Form1 with CheckedListBox1 and   
    ' Button1  
    Option Strict On  
    Option Explicit On  
    Public Class Form1  
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
    		CheckedListBox1.Enabled = Not CheckedListBox1.Enabled  
    	End Sub  
    End Class  
      
    

  2. Castorix31 90,681 Reputation points
    2022-06-25T16:49:12.657+00:00

    You can handle events like ItemCheck

    Dim bDisableCheck As Boolean = False  
    

    After ListView creation :

     bDisableCheck = True  
    

    ItemCheck :

    Private Sub ListView1_ItemCheck1(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck  
        If bDisableCheck Then  
            e.NewValue = e.CurrentValue  
        End If       
    End Sub  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.