VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
checkedlistbox question Posted by eman2a on 17 Sept 2004 at 8:48 PM
Can anyone please tell me what event fires when an item in a checkedlistbox is checked/unchecked? I have a list of items that I'm adding to a database. One of the columns in the row changes depending on whether the item is checked. I can't seem to find an example of this anywhere.

Your help is greatly appreciated.

Jim (eman2a)
Report
Re: checkedlistbox question Posted by kainsworth on 18 Sept 2004 at 5:08 AM
There are a couple of ways of doing this. here's one (taken from MSDN) which uses the CheckedItems property:
' Determine if there are any items checked.
If CheckedListBox1.CheckedItems.Count <> 0 Then
   ' If so, loop through all checked items and print results.
   Dim x As Integer
   Dim s As String = ""
   For x = 0 To CheckedListBox1.CheckedItems.Count - 1
      s = s & "Checked Item " & (x + 1).ToString & " = " & CheckedListBox1.CheckedItems(x).ToString & ControlChars.CrLf
   Next x
   MessageBox.Show(s)
End If

You can also use the GetItemChecked Method in pretty much the same way.
Dim i As Integer
Dim s As String
s = "Checked Items:" & ControlChars.CrLf
For i = 0 To (CheckedListBox1.Items.Count - 1)
   If CheckedListBox1.GetItemChecked(i) = True Then
      s = s & "Item " & (i + 1).ToString & " = " & CheckedListBox1.Items(i).ToString & ControlChars.CrLf
   End If
Next
MessageBox.Show(s)

If you want to pursue the available methods even further, there are also GetItemCheckState method and the CheckedIndices Collection to look at.
Let me know if you need more info on any of these.

Ged


Report
Re: checkedlistbox question Posted by eman2a on 18 Sept 2004 at 8:34 AM
: There are a couple of ways of doing this. here's one (taken from MSDN) which uses the CheckedItems property:
:
: ' Determine if there are any items checked.
: If CheckedListBox1.CheckedItems.Count <> 0 Then
:    ' If so, loop through all checked items and print results.
:    Dim x As Integer
:    Dim s As String = ""
:    For x = 0 To CheckedListBox1.CheckedItems.Count - 1
:       s = s & "Checked Item " & (x + 1).ToString & " = " & CheckedListBox1.CheckedItems(x).ToString & ControlChars.CrLf
:    Next x
:    MessageBox.Show(s)
: End If
: 

: You can also use the GetItemChecked Method in pretty much the same way.
:
: Dim i As Integer
: Dim s As String
: s = "Checked Items:" & ControlChars.CrLf
: For i = 0 To (CheckedListBox1.Items.Count - 1)
:    If CheckedListBox1.GetItemChecked(i) = True Then
:       s = s & "Item " & (i + 1).ToString & " = " & CheckedListBox1.Items(i).ToString & ControlChars.CrLf
:    End If
: Next
: MessageBox.Show(s)
: 

: If you want to pursue the available methods even further, there are also GetItemCheckState method and the CheckedIndices Collection to look at.
: Let me know if you need more info on any of these.
:
: Ged
:
:
:
Thanx...That's exactly what I was looking for!

Jim (eman2a)




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.