[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with getting checked items of checkedlistbox

Posted on 2009-04-27
2
Medium Priority
?
514 Views
Last Modified: 2012-05-06
Hi

Please create a form with a CheckedListBox and a RichTextBox. Run code, check/uncheck items in left Checkedlistbox and compare results in right Richtextbox.

Why do I get wrong results? What I'm doing wrong?

Many thanks.
Public Class Form1
 
    Dim strOutput As String
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strCheckBoxText(2) As String
        For i = 0 To 2
            CheckedListBox1.Items.Add("Item " & i.ToString)
        Next
        FillRichTextBox()
    End Sub
 
    Private Sub CheckedListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckedListBox1.Click
        FillRichTextBox()
    End Sub
 
    Sub FillRichTextBox()
        strOutput = ""
        For i = 0 To 2
            strOutput = strOutput & CheckedListBox1.GetItemChecked(i).ToString & vbCrLf
        Next
        RichTextBox1.Text = strOutput
    End Sub
 
End Class

Open in new window

0
Comment
Question by:ptea
2 Comments
 
LVL 5

Accepted Solution

by:
karstieman earned 2000 total points
ID: 24248097
You should change the CheckedListBox1_Click with CheckedListBox1_mouseup.
Here's the new code you should try:


Public Class Form1
    Dim i As Integer = Nothing
    Dim strOutput As String
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strCheckBoxText(2) As String
        For i = 0 To 2
            CheckedListBox1.Items.Add("Item " & i.ToString)
        Next
        FillRichTextBox()
    End Sub
    Private Sub CheckedListBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseUp
        FillRichTextBox()
    End Sub
    
 
    Sub FillRichTextBox()
        strOutput = ""
        For i = 0 To 2
            strOutput = strOutput & CheckedListBox1.GetItemChecked(i).ToString & vbCrLf
        Next
        RichTextBox1.Text = strOutput
    End Sub
 
  
End Class

Open in new window

0
 

Author Comment

by:ptea
ID: 24249130
Many thanks, that works.

From other source; also would work:
 (see code)

    Private Sub CheckedListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedValueChanged
        FillRichTextBox()
    End Sub

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question