CheckedListBox class question

  • Thread starter Thread starter Mike Kim
  • Start date Start date
M

Mike Kim

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
 
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.
 
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
 
Right on Fergus !! you are right on the money again.
Thank you very much for your help.
 
Back
Top