PC Review


Reply
Thread Tools Rate Thread

DataSource at design time

 
 
Stephen
Guest
Posts: n/a
 
      3rd Oct 2003
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


 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      3rd Oct 2003
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
>
>



 
Reply With Quote
 
Stephen
Guest
Posts: n/a
 
      3rd Oct 2003
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
> >
> >

>
>



 
Reply With Quote
 
Kevin Yu
Guest
Posts: n/a
 
      3rd Oct 2003
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
| > >
| > >
| >
| >
|
|
|

 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      3rd Oct 2003
Stephen,
> Simplicity, speed and the guarantee that the data is exactly the same.

..NET
> is supposed to make for rapid app development after all.

Huh? Based on the above it sounds like you want to use ListBox.Items. It is
simply, it is speedy. I'm not sure what you are comparing to be exactly the
same.

> Is there a way to refresh the ListBox?

Yes binding to a class that implements IBindingList such as DataTable
(DataView) will refresh the ListBox automatically.

Also using the ListBox.Items collection instead of an ArrayList will cause
the ListBox to be refreshed.

I have not tried Kevin's code I would expect Kevin's code to also refresh
the ListBox, for the reason's Kevin identified.

Hope this helps
Jay

"Stephen" <(E-Mail Removed)> wrote in message
news:ePMyu%(E-Mail Removed)...
> 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox DataSource Design binding problem ramses1 Microsoft VB .NET 1 6th Feb 2006 12:10 PM
setting datagrid datasource in design to table on vs 2005 beta 2? Kimberly Microsoft Dot NET Compact Framework 0 16th Aug 2005 10:39 PM
DataSource property to control design time =?Utf-8?B?TW9ydGVuIEx5aHI=?= Microsoft Dot NET Framework Forms 1 1st Jun 2004 09:24 AM
design time DataSource in VB Stephen Microsoft Dot NET Framework Forms 1 3rd Oct 2003 01:26 PM
Combo Datasource problem, 1st time OK, 2nd time Not GW Microsoft Dot NET Compact Framework 1 15th Aug 2003 12:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:16 PM.