473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Question on a CheckedListBox.

Hi there,

I'm having this dilema with a checkedlistbox.

I have an array of items in there, what I want to accomplish is the
following;

The user could check all the items in the checkedlistbox, but always have at
list one item always checked. so if the user has the last item checked and
he/she wants to uncheck it, the item should reset it self to a checked state
again.

Been trying to think of the login that this should follow, but I just not
having luck here.

Any ideas, hits, advices would so much Appreciated

Thanks,

Manuel

Nov 20 '05 #1
2 2260
Not the answer to YOUR problem, but here is some code I have that ensures
that at least one and only one item is checked in a checkedlistbox. Might
give you some ideas to get started.

(background: my list is a list of approvers, the rule is that there can only
be one "primary" approver. you indicate primary by placing the checkmark)

Looking at this code right now is making my head hurt, but it all made sense
to me a few months ago. :^)

HTH,
Greg

Private Programatically As Boolean
Private Loading As Boolean

Sub New()
Loading = True
' bind checkedlistbox here
Loading = False
End Sub

Private Sub lstApprovers_ItemCheck(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemCheckEventArgs) Handles lstApprovers.ItemCheck

If Loading Then Exit Sub

If e.NewValue = CheckState.Checked And e.CurrentValue =
CheckState.Unchecked Then

If DirectCast(sender, CheckedListBox).CheckedItems.Count > 0
Then Call ClearCheckBoxes(DirectCast(sender, CheckedListBox), False)

ds.Tables("Approvers").Rows.Find(CType(lstApprover s.Items(e.Index),
ListBoxItem).Data)("Primary") = 1
End If

If Not Programatically And e.NewValue = CheckState.Unchecked Then
e.NewValue = CheckState.Checked
ElseIf e.NewValue = CheckState.Unchecked Then

ds.Tables("Approvers").Rows.Find(CType(lstApprover s.Items(e.Index),
ListBoxItem).Data)("Primary") = 0
ElseIf e.NewValue = CheckState.Checked Then

ds.Tables("Approvers").Rows.Find(CType(lstApprover s.Items(e.Index),
ListBoxItem).Data)("Primary") = 1

End If
End Sub

Private Sub ClearCheckBoxes(ByRef CheckedList As CheckedListBox, ByVal
ClearSelected As Boolean)
Programatically = True
Dim i As Integer

If CheckedList.CheckedItems.Count > 0 Then

For i = 0 To CheckedList.Items.Count - 1

If CheckedList.GetItemChecked(i) Then

If CheckedList.SelectedIndex = i Then

If ClearSelected Then CheckedList.SetItemChecked(i,
False)

Else

CheckedList.SetItemChecked(i, False)
End If

End If

Next

End If
Programatically = False

End Sub
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:xdDNc.123017$eO.64363@edtnps89...
Hi there,

I'm having this dilema with a checkedlistbox.

I have an array of items in there, what I want to accomplish is the
following;

The user could check all the items in the checkedlistbox, but always have at list one item always checked. so if the user has the last item checked and
he/she wants to uncheck it, the item should reset it self to a checked state again.

Been trying to think of the login that this should follow, but I just not
having luck here.

Any ideas, hits, advices would so much Appreciated

Thanks,

Manuel

Nov 20 '05 #2
Thanks Greg. This is giving some ideas for sure.

Thanks again,

Manuel

"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:xdDNc.123017$eO.64363@edtnps89...
Hi there,

I'm having this dilema with a checkedlistbox.

I have an array of items in there, what I want to accomplish is the
following;

The user could check all the items in the checkedlistbox, but always have at list one item always checked. so if the user has the last item checked and
he/she wants to uncheck it, the item should reset it self to a checked state again.

Been trying to think of the login that this should follow, but I just not
having luck here.

Any ideas, hits, advices would so much Appreciated

Thanks,

Manuel

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matt C. | last post by:
Does the CheckedListBox support DisplayMember/ValueMember? I have been trying to use these properties with the CheckedListBox and they are not working. I see from Google that databinding is not...
0
by: | last post by:
David, A partial answer to your question: The 'MultiColumn' property of a CheckedListBox does not cause it to display multiple FIELDS of an item... it causes it to display the items...
4
by: Matthew | last post by:
Hi, I am using a checkedlistbox on a windows form and binding it to a collection of classes. clbAliases is the checkedlistbox control selectedplace is a class with property placealiases.This...
8
by: Derek Martin | last post by:
Here is some code that I need help with please: Dim result As New ArrayList Try For i = 0 To objecttest1.PersonList.person_returnnumber - 1 result =...
4
by: Moondog | last post by:
Simple question: How can I test if an item has been checked in a CheckedListBox? My scenario is if a user clicks on my CheckedListBox, and the item has not been checked yet, do some event, if...
9
by: Capt_Ron | last post by:
Hello, I would like to set the value of the item in the checked list box. I have a datareader that has 2 columns. PK and TEXT I want the TEXT as the Item and the PK as the Value. I can not...
0
by: Terry Olsen | last post by:
Dim dirs() as string = Directory.GetDirectories(MyPath) CheckedListBox.DataSource = dirs CheckedListBox.Update For I as Integer = 0 To CheckedListBox.Items.Count - 1...
6
by: Steve Teeples | last post by:
Can someone show me an example of how to place a "CheckedListBox" property within a PropertyGrid? -- ----------- Thanks, Steve
2
by: bh | last post by:
In the Listbox, there are properties for DisplayMember and ValueMember, just like the combobox, however, those properties are not present for the CheckedListBox. Does this mean that the only...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.