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.
Here's what I've come up with to meet your requirements. Hopefully you can work with it and shape it to your desires. - Public Class Form1
-
Dim btnClick As Boolean = False
-
-
Private Sub CheckForChecks(ByVal e As System.Windows.Forms.ItemCheckEventArgs)
-
If btnClick = True Then
-
btnClick = False
-
Else
-
e.NewValue = e.CurrentValue
-
End If
-
End Sub
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
btnClick = True
-
CheckedListBox1.SetItemChecked(1, True)
-
End Sub
-
-
Private Sub CheckedListBox1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
-
Call CheckForChecks(e)
-
End Sub
-
-
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
-
Dim txtBoxInt As Integer = TextBox1.Text
-
Dim cLBInt As Integer = CheckedListBox1.SelectedItem
-
If txtBoxInt > cLBInt Then
-
MsgBox(CheckedListBox1.SelectedIndex)
-
End If
-
End Sub
-
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
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.
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.
Here's what I've come up with to meet your requirements. Hopefully you can work with it and shape it to your desires. - Public Class Form1
-
Dim btnClick As Boolean = False
-
-
Private Sub CheckForChecks(ByVal e As System.Windows.Forms.ItemCheckEventArgs)
-
If btnClick = True Then
-
btnClick = False
-
Else
-
e.NewValue = e.CurrentValue
-
End If
-
End Sub
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
btnClick = True
-
CheckedListBox1.SetItemChecked(1, True)
-
End Sub
-
-
Private Sub CheckedListBox1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
-
Call CheckForChecks(e)
-
End Sub
-
-
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
-
Dim txtBoxInt As Integer = TextBox1.Text
-
Dim cLBInt As Integer = CheckedListBox1.SelectedItem
-
If txtBoxInt > cLBInt Then
-
MsgBox(CheckedListBox1.SelectedIndex)
-
End If
-
End Sub
-
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.
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.
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).
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
by: Vikram |
last post by:
How to disble a particular checkbox list item in a checkbox list
|
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?
|
by: James Lennon |
last post by:
Does anyone know how to disable a single check box in a Windows Forms
TreeView control.
|
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..........?
|
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"...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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 ...
| |