473,386 Members | 1,820 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,386 software developers and data experts.

CheckedListBox class question

Hi all,

I've populated a checkedlistbox control with a dataset as follows:

chklstTasks.DataSource = dsTask.Tables("Task").DefaultView
chklstTasks.DisplayMember = "header"
chklstTasks.ValueMember = "task_id"

and in my button_click event, i would like to traverse the items in this
chklstTasks and if an item is
checked, i want to pop a message box to display "header" and "task_id" of
that item.

i tried as follow and got stuck. any help is appreciated. thanks in advance.

For i = 0 To chklstTasks.CheckedItems.Count - 1
' how to i check if each item is checked and if check, what is the
task_id?

Next
Nov 19 '05 #1
2 3073
Hi Fergus,
Thanks much. That's exactly what i was looking for. It works !!

I have one more question:
i want to traverse the whole list using Items collection and check each
item with checkstate and do something based on their state. Can I still use
DataRowView?
How do I use CheckState? from which object?
I tried ..

For i = 0 To chklstTasks.Items.Count - 1
drvTask = CType(chklstTasks.Items(i), DataRowView)
' i want to do something like this ..
selec case drvTask.CheckState
case 'unchecked
case ' checked
case ' intermediate
end select
Next

thanks again.
"Fergus Cooney" <wo****@tesco.net> wrote in message
news:#x**************@TK2MSFTNGP10.phx.gbl...
Hi Mike,

chklstTasks.Items contains the list of ALL the items in the list, while chklstTasks.CheckedItems contains ONLY those which have been checked. So
your first task (get all the checked items) is done for you.

Each of the items in chklstTasks.CheckedItems is a DataRowView, however it is stored as an Object type. So you'll need to assign each one to a
DataRowView in order to access it.

Then it's familiar stuff.

Dim drvTask As DataRowView
Dim sInfo As String

For I = 0 To chklstTasks.CheckedItems.Count - 1
drvTask = chklstTasks.CheckedItems (I)
sInfo = drvTask ("header") & ", " & drvTask ("task_id")
'Do something with sInfo
Next

Best wishes,
Fergus

Nov 19 '05 #2
Howdy Mike,

One question - three question marks!!! - no problem :-)

Q. Can I still use DataRowView?
A. Yes, you can still use DataRowView. In fact, in your case, you must,
because that's what the items are. I note that in your code you are doing a
type conversion. Have you found that you need to? It worked fine when I did
it without:
drvTask = chklstTasks.Items(i)
vs.
drvTask = CType (chklstTasks.Items(i), DataRowView)
Q. How do you use CheckState? From which object?
A. Using chklstTasks.GetItemCheckState(i)

Dim S as String = ""
Dim I As Integer
For I = 0 To chklstTasks.Items.Count - 1
Select Case chklstTasks.GetItemCheckState(i)
Case CheckState.Checked: S = S & "X"
Case CheckState.Indeterminate: S = S & "?"
Case CheckState.Unchecked: S = S & "O"
End Select
Next
S = S: Stop

Regards,
Fergus
Nov 19 '05 #3

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

Similar topics

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: Reza | last post by:
Hi, I want to check one of the memebrs of a checkedListbox based on its value. I 'm getting a number(say 1355) from another control and based on that number I want to check an item which its...
1
by: Hrvoje Voda | last post by:
I have a users name in checkedlistBox and usersID in listBox. How to connect those to lists to get a userID from listBox depending on userName from checkedlistBox? Hrcko
1
by: xiuyu_0129 | last post by:
Hi All, How do I store a string value for an item in a CheckedListBox in Windows Form? For a web based application, CheckBoxList allowed us to store 2 string values for the item in it. How do...
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 =...
2
by: Manuel Canas | last post by:
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...
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...
5
by: mabond | last post by:
Hi Can't believe I've not been able to find the answer to this in the on-line help. I have a CheckedListBox which, via a timer control, is populated with the names of files in a network...
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
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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,...
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...

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.