473,325 Members | 2,872 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,325 software developers and data experts.

constrain numbers of item check in CheckedListBox

Hei
Hi,

any ideas how to constrain the numbers of item can check in CheckListBox. i
would force user can only check one item.

thx
William
Nov 20 '05 #1
8 9404
Sounds like a combobox would work better, but try this:

Private Sub List1_ItemCheck(Item As Integer)
If List1.SelCount > 1 Then
List1.Selected(Item) = False
End If
End Sub

"Hei" <ch******@msn.com> wrote in message
news:uQ*************@TK2MSFTNGP09.phx.gbl...
Hi,

any ideas how to constrain the numbers of item can check in CheckListBox. i would force user can only check one item.

thx
William

Nov 20 '05 #2
Cor

"Hei"

Sounds like radiobuttons on a groupbox would work better

Goes automaticly

Cor
Nov 20 '05 #3
Hei

i have try follow code, but some time not work or the respond is slow

With CheckedListBox1
If .CheckedItems.Count > 1 Then
.SetItemChecked(.Items.IndexOf(.CheckedItems(0)), False)
End If
End With

"Hei" <ch******@msn.com> wrote in message
news:uQ*************@TK2MSFTNGP09.phx.gbl...
Hi,

any ideas how to constrain the numbers of item can check in CheckListBox. i would force user can only check one item.

thx
William

Nov 20 '05 #4
just a thought (i would prefer this as a user)
how about removing all the selections and setting the checked of the last
selected item (e.index) to true?
slightly diferent way of working
but for this i would also use a combobox
"Hei" <ch******@msn.com> wrote in message
news:ek**************@TK2MSFTNGP12.phx.gbl...

i have try follow code, but some time not work or the respond is slow

With CheckedListBox1
If .CheckedItems.Count > 1 Then
.SetItemChecked(.Items.IndexOf(.CheckedItems(0)), False) End If
End With

"Hei" <ch******@msn.com> wrote in message
news:uQ*************@TK2MSFTNGP09.phx.gbl...
Hi,

any ideas how to constrain the numbers of item can check in
CheckListBox. i
would force user can only check one item.

thx
William


Nov 20 '05 #5
Private Sub List1_ItemCheck(Item As Integer)
Static intLastChecked As Integer
If Item <> intLastChecked Then
List1.Selected(intLastChecked) = False
List1.Selected(Item) = True
intLastChecked = Item
End If
End Sub

Regards,

Rubén Vigón
Microsoft MVP Visual Basic
Nov 20 '05 #6
Cor
Hi Ericj,

I would for sure make dynamicly a radiobutton array on a groupbox if the
push is so important.
but for this i would also use a combobox


Cor
Nov 20 '05 #7
Hei,
Is this a VB.NET question or a VB6 question? as you posted to both groups.

The solution you receive for VB6 will not work in VB.NET and visa versa.

How do you want it to behave. Once an item is checked you cannot check a
second one? Or the last item checked is the only item checked?

Why are you even bothering with a CheckListBox if you only one item can be
selected? A normal ListBox supports selecting a single item, so I would
STRONGLY recommend a normal ListBox or even a ComboBox to save screen space.

Also if I only had a handful of items, I would consider, as Cor suggested,
using Radio Buttons.

If I had a real need for a CheckListBox, I would handle the ItemCheck event.
In VB.NET The ItemCheck event itself allows you to control whether the item
should be checked or not. Seeing as VB.NET fully supports customizing
controls via inheritance I would create a new class derived from
CheckListBox that would encapsulate the currently checked item and handle
the ItemCheck within itself to ensure that only one item was ever checked...

Hope this helps
Jay

"Hei" <ch******@msn.com> wrote in message
news:uQ*************@TK2MSFTNGP09.phx.gbl...
Hi,

any ideas how to constrain the numbers of item can check in CheckListBox. i would force user can only check one item.

thx
William

Nov 20 '05 #8
Hei

thanks a lot for every expert
my problem was fix by above ideal .

Hei.
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hei,
Is this a VB.NET question or a VB6 question? as you posted to both groups.

The solution you receive for VB6 will not work in VB.NET and visa versa.

How do you want it to behave. Once an item is checked you cannot check a
second one? Or the last item checked is the only item checked?

Why are you even bothering with a CheckListBox if you only one item can be
selected? A normal ListBox supports selecting a single item, so I would
STRONGLY recommend a normal ListBox or even a ComboBox to save screen space.
Also if I only had a handful of items, I would consider, as Cor suggested,
using Radio Buttons.

If I had a real need for a CheckListBox, I would handle the ItemCheck event. In VB.NET The ItemCheck event itself allows you to control whether the item should be checked or not. Seeing as VB.NET fully supports customizing
controls via inheritance I would create a new class derived from
CheckListBox that would encapsulate the currently checked item and handle
the ItemCheck within itself to ensure that only one item was ever checked...
Hope this helps
Jay

"Hei" <ch******@msn.com> wrote in message
news:uQ*************@TK2MSFTNGP09.phx.gbl...
Hi,

any ideas how to constrain the numbers of item can check in
CheckListBox. i
would force user can only check one item.

thx
William


Nov 20 '05 #9

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

Similar topics

1
by: Tamir Gal | last post by:
Hi, I'm using the CheckedListBox control, and I'm wondering if there is a way to let the user check an item in the list without also selecting it... Any ideas? Thanks in advance, Tamir.
1
by: fotis | last post by:
hi there can anybody tell me if it's possible and how can i change the name of a CheckedListBox item.I have used the Add method to insert the item. thank you
2
by: Dave Veeneman | last post by:
Is there a simple way to check the status of an item as checked or unchecked in a CheckedListBox? I need to cycle through a CheckedListBox and take one of two actions for each item, depending on...
2
by: Grant | last post by:
Hello, When I am adding things to my checkedListBox - how do I check an item as it is added? In other words I loop through an array adding text to the checkedListBox and when the corresponding...
3
by: Dean Slindee | last post by:
In a checked listbox, I am allowing drag/drop of the items within (resequencing). Problem is, when dropping a checked item, the checked state always reverts to unchecked (unwanted). Anyone know...
26
by: Simon Jefferies | last post by:
Hello, I am trying to add an item to a checked list box, like: clbList.Items.add("Hello",true) I get an error back: Run-time exception thrown: System.ArgumentOutOfRangeException -...
1
by: John | last post by:
Is there a way to make the font for the selected item(s) bold in a CheckedListBox? Thanks, John
1
by: Cylix | last post by:
When I using the checkedlistbox1.items.add, I found that it can be set the item is checked defaultly. But how can I using the code to check an item in the list after defined the list?? Thanks.
6
by: painkiller | last post by:
language: vb.net environment: windows forms .net : v1.1 i am having a checkedlistbox control that display document category such as text, image, video, audio etc. these values are coming from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.