design time databinding

S

Stephen

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("XXX") 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
 
K

Kevin Yu

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" <[email protected]>
| Subject: design time databinding
| Date: Thu, 2 Oct 2003 22:07:17 -0400
| Lines: 18
| 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: <[email protected]>
| 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!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:143300
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| 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("XXX") 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
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top