Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » .NET Programming » Visual Basic .NET/2005/2008 » How to Add Items to a Checked List Box


How to Add Items to a Checked List BoxExpand / Collapse
Author
Message
Posted 10/10/2008 8:58:45 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/10/2008 4:02:17 PM
Posts: 4, Visits: 4
I have a program that so far downloads an XML file, parses it, stores it in an ArrayList and then reads the ArrayList to add items to a Checked List Box, which is on a different form from where the ArrayLists are made and stored as public class variables.

After I construct the ArrayLists I used the following bit of

testForm.testList.Items.Add("Test String", True)


The code runs properly and can be accessed again using

testForm.testList.Items()


When I hide the current form and show "testForm" (the form holding the Checked List Box) none of the items I've added show up. Any ideas?
Post #25956
Posted 10/10/2008 9:03:25 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/10/2008 4:02:17 PM
Posts: 4, Visits: 4
Another note, all this code about downloading XML, parsing it, and adding items into a checked list box is done inside a background worker. I'm not sure if that will make a different.
Post #25957
Posted 10/10/2008 11:33:57 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Yesterday @ 3:21:14 PM
Posts: 845, Visits: 5,124
I think you are right it is in your background worker. You can't directly commucate with controls. Try this:

Set the WorkerReportsProgress to true.

    Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
        BackgroundWorker1.WorkerReportsProgress = True
        BackgroundWorker1.RunWorkerAsync()
    End Sub

In the DoWork:

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim x As Long = 0
        Do While x < 100
            BackgroundWorker1.ReportProgress(1, "Test " & CStr(x))
            x += 1
        Loop
    End Sub

The one is just there because I have to have something there. The string is what you want to put in the checked listbox.

In the ProgressChanged:

    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As ObjectByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        Form2.CheckedListBox1.Items.Add(e.UserState)
    End Sub

 Edit: You cannot see anything until the worker has finished.

Wayne

I know enough to be dangerious.

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.

Post #25958
Posted 10/10/2008 4:02:35 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/10/2008 4:02:17 PM
Posts: 4, Visits: 4
That was it! Thanks a lot! Topic solved.
Post #25960
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Brian, Peter

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 8:16am