Hi Stephen,
Since the refresh of ListBox doesn't work when items are added or removed
from the arraylist, the simplest workaround is to reset the DataSource
property of the ListBox. you can try the following code to achieve this.
arraylist.Add("Whatever")
listbox.DataSource = Nothing
listbox.DataSource = arraylist
You cannot omit the second line, because if you simply set the
listbox.DataSource to arraylist, the listbox will check if the new
DataSource is the same as the old one. (The listbox doesn't know that the
arraylist has changed, it only knows that they are the same object
reference.)
Does this answer your question? If anything is unclear, please feel free to
reply to the post.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| From: "Stephen" <(E-Mail Removed)>
| References: <#(E-Mail Removed)>
<(E-Mail Removed)>
| Subject: Re: DataSource at design time
| Date: Thu, 2 Oct 2003 23:37:35 -0400
| Lines: 59
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <ePMyu#(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: c-66-177-177-97.se.client2.attbi.com 66.177.177.97
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:143316
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Simplicity, speed and the guarantee that the data is exactly the same.
..NET
| is supposed to make for rapid app development after all. Is there a way
to
| refresh the ListBox? I tried rebinding it after the data changed but it
| didn't work. Maybe I have to unbind it then rebind it.
|
| "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> wrote in
message
| news:(E-Mail Removed)...
| > Stephen,
| > At design time the only 'native' collection that I know of you can use
is
| a
| > DataTable (specifically a DataTable in a DataSet.)
| >
| > You can then add new rows to the DataTable's Rows collection and they
will
| > show up in the List.
| >
| > The reason adding items to the ArrayList do not show up in the ListBox
is
| > that the ArrayList does not support the ListChanged event (part of the
| > IBindingList interface).
| >
| > Is there a reason you want to bind to a DataSource as opposed to simply
| > adding the items to the ListBox.Items collection (via the
| ListBox.Items.Add
| > method)?
| >
| > Hope this helps
| > Jay
| >
| > "Stephen" <(E-Mail Removed)> wrote in message
| > news:%(E-Mail Removed)...
| > > IN VB.NET
| > > I have a form with a ListBox and would like to set the DataSource
| property
| > > at design-time but I can't seem to declare any kind of variable that
| will
| > > show up in the list. I have tried a traditional array, ArrayList,
| > > Collection as public vars in the Form Class's Declarations section.
| > Setting
| > > the DataSource property to any of these works fine at run time.
| > >
| > > I want to do it at design time because after I change the Collection,
it
| > > doesn't update it in the ListBox, even though breaking showed that the
| > > Collection.Count property had gone up. I first add to it in code with
| > > Coll.Add("WHATEVER") and it shows up fine, before and after binding.
| But
| > I
| > > try
| > > to do this: Coll.Add(TextBox1.Text) and it doesn't show up in the
| ListBox
| > > but is apparently being added to the collection object just fine.
| > >
| > > Any answer to either of these questions would be helpful
| > > Thanks,
| > > Stephen
| > >
| > >
| >
| >
|
|
|
|