473,467 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB disable checkbox checking by user?

5 New Member
I have a program where a checkbox greatly affects its outcome.
What it is suppose to do is, when the value of an item is less then the value of a text box, then the program will check it off, and then re-calculate the remaining numbers and update a label.

I want to be able to programically check/uncheck items BUT I dont want the user to manually be able to do so ALL AT THE SAME TIME, I want the item to still be "selected" (highlighted) when they click on it.
Jan 22 '14 #1

✓ answered by Luk3r

Here's what I've come up with to meet your requirements. Hopefully you can work with it and shape it to your desires.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim btnClick As Boolean = False
  3.  
  4.      Private Sub CheckForChecks(ByVal e As System.Windows.Forms.ItemCheckEventArgs)
  5.         If btnClick = True Then
  6.             btnClick = False
  7.         Else
  8.             e.NewValue = e.CurrentValue
  9.         End If
  10.     End Sub
  11.  
  12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  13.         btnClick = True
  14.         CheckedListBox1.SetItemChecked(1, True)
  15.     End Sub
  16.  
  17.     Private Sub CheckedListBox1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
  18.         Call CheckForChecks(e)
  19.     End Sub
  20.  
  21.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  22.         Dim txtBoxInt As Integer = TextBox1.Text
  23.         Dim cLBInt As Integer = CheckedListBox1.SelectedItem
  24.         If txtBoxInt > cLBInt Then
  25.             MsgBox(CheckedListBox1.SelectedIndex)
  26.         End If
  27.     End Sub
  28. End Class
I suggest you create a new project and play with this code first. It only requires a Button, a CheckedListBox, and a TextBox.

5 3489
Luk3r
300 Contributor
If I'm understanding correctly, then you'd want to setup the Textbox.TextChanged event. When the text is changed, you want your code to run where it's checking for the value of the item and then tell it that Checkbox.Checked = True. Then, setup a Checkbox.CheckChanged... your code would say, If Checkbox.checked = True then re-calculate. Hope this helps! If it's not a good explanation, show us what you're working with or give us a little more detail and I'd be more than happy to show you an example of how I would personally do it.
Jan 22 '14 #2
Leftic
5 New Member
Well, what I am exactly trying to do is:

In the checkedlistbox1, the user CANNOT check off items during runtime
BUT, they can still click on the item and it will highlight the item as it would if they COULD check off items.
So now, they can ONLY control the checking of the items off by this textbox1.

So, lets say the first item in listbox was 50
And they enter 100 in Textbox1
Since 100 is infact > 50, the program will simply find this item that = "50" and check it off

But, if you so wish, you can click on the item, and it will highlight the item from the listbox so you can see where you are at.

Right no I dont have any code that deals with that, but on the load function of the form, I have the listbox's selection mode set to "none". The issue with this method though is, they CANT check off any items (which is what I want), but at the same time, they also cannot select (highlight) any items, which is a problem. I want them to be able to both NOT be able to check off items, AND still be able to select (highlight) the item. And when I say select (highlight), I literally mean, how listboxes do, when you click on an item, it will literally select it, and you know this by the background of that item becoming dark blue like it is "highlighted".

If that explanation helps.
Jan 23 '14 #3
Luk3r
300 Contributor
Here's what I've come up with to meet your requirements. Hopefully you can work with it and shape it to your desires.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim btnClick As Boolean = False
  3.  
  4.      Private Sub CheckForChecks(ByVal e As System.Windows.Forms.ItemCheckEventArgs)
  5.         If btnClick = True Then
  6.             btnClick = False
  7.         Else
  8.             e.NewValue = e.CurrentValue
  9.         End If
  10.     End Sub
  11.  
  12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  13.         btnClick = True
  14.         CheckedListBox1.SetItemChecked(1, True)
  15.     End Sub
  16.  
  17.     Private Sub CheckedListBox1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
  18.         Call CheckForChecks(e)
  19.     End Sub
  20.  
  21.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  22.         Dim txtBoxInt As Integer = TextBox1.Text
  23.         Dim cLBInt As Integer = CheckedListBox1.SelectedItem
  24.         If txtBoxInt > cLBInt Then
  25.             MsgBox(CheckedListBox1.SelectedIndex)
  26.         End If
  27.     End Sub
  28. End Class
I suggest you create a new project and play with this code first. It only requires a Button, a CheckedListBox, and a TextBox.
Jan 23 '14 #4
Leftic
5 New Member
Wow, thank you! (after making some slight variations so it worked for my program) the code worked perfectly and did exactly what I wanted it to do! Thanks again for the help.
Jan 25 '14 #5
Luk3r
300 Contributor
You're welcome and glad I could help.

Edit**: Also, for anyone else that may use this, Call CheckForChecks2(e) should just be Call CheckForChecks(e).
Jan 26 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Mike Lopez | last post by:
Hello. I need to set a checkbox to the "checked" state and prevent the user from unchecking it. I tried using "disabled", but then the value is not passed on the Post to an ASP page. Anyone...
2
by: MT | last post by:
Hi, I am currently validating an XML file against a Schema using XMLValidatingReader. The schema actually contains ranges for particular elements and I have been using it to detect range errors...
2
by: Maziar Aflatoun | last post by:
Hi everyone, I am reading and displaying data rows from my database where the first column contains the Status checkbox. I like to enable my users to change the status of individual rows by...
1
by: Vikram | last post by:
How to disble a particular checkbox list item in a checkbox list
7
by: sheldonlg | last post by:
I have a checkbox that I set by php code to be either "checked" or "". I want to disable the ability of the user to check or uncheck it. I tried "readonly", but that didn't work. Any suggestions?
3
by: James Lennon | last post by:
Does anyone know how to disable a single check box in a Windows Forms TreeView control.
2
by: madhusudanreddy | last post by:
hi iam new to scripts, i have a dropdownlist and ckeckbox ,i want to disable the ckeckbox when the user selects the second option of dropdownlist .how to do this please help me..........?
2
by: tvnaidu | last post by:
How can I disable checkbox when it is selected Kernel?. <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td align="right" width="40%" valign="top"...
14
by: ZakeerSharief | last post by:
Hi,I have say 10 checkbox in my form. In which i should be able to select only 2 checkboxes. Once 2 checkbox are selected then the remaining checkboxes should be disabled. And which ever checkboxes...
3
by: SeadooRider | last post by:
The following code works for one checkbox with same code with different checkbox and textbox names, however this one brings up the msgbox even if the required field it is checking DOES have text in...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.