PC Review


Reply
Thread Tools Rate Thread

CheckedListBox class question

 
 
Mike Kim
Guest
Posts: n/a
 
      25th Aug 2003
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


 
Reply With Quote
 
 
 
 
Mike Kim
Guest
Posts: n/a
 
      25th Aug 2003
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" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      26th Aug 2003
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


 
Reply With Quote
 
Mike Kim
Guest
Posts: n/a
 
      26th Aug 2003
Right on Fergus !! you are right on the money again.
Thank you very much for your help.

"Fergus Cooney" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CheckedListBox Question Newbie Coder Microsoft VB .NET 1 3rd Dec 2006 07:57 PM
CheckedListbox Question Moondog Microsoft VB .NET 4 18th Oct 2004 11:59 PM
A question about CheckedListBox. Microsoft C# .NET 0 9th Sep 2004 11:39 PM
CheckedListBox question Stephen Haunts Microsoft Dot NET Framework Forms 1 24th Jun 2004 06:52 PM
CheckedListBox Question Derek Martin Microsoft VB .NET 4 7th Apr 2004 11:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:13 PM.