Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

binding items of a ListBox with an ArrayList

1 view
Skip to first unread message

Michael Dengler

unread,
Sep 18, 2002, 5:11:30 PM9/18/02
to
Hi,
I want to bind the items of a listbox with them of an arraylist under
the following conditions.
1. If I remove or add an object to the listbox, the arraylist must do
the same.
2. The same progress has to work inversely.

I know the DataBinding of Controls, but afaik can you only bind one
property with another.

I hope you can help me!
Thanks,
Michael

Ryan Dawson

unread,
Sep 18, 2002, 10:17:40 PM9/18/02
to
Michael,

In order to do this you can add the actual object of the ArrayList, not the
string. Then when the item changes, the ArrayList will reflect the changes.
But, in order to do this, you must inherit the ArrayList class and write
your own class which provides methods for ToString (), because this is what
the listbox will query to get the string to display in the listbox. Include
any other override functions as needed.

--

Hope this Helps.

Ryan Dawson


"Michael Dengler" <ma...@dengl.com> wrote in message
news:3D88EC0...@dengl.com...

Michael Dengler

unread,
Sep 19, 2002, 6:19:01 AM9/19/02
to
Ryan Dawson wrote:
> Michael,
>
> In order to do this you can add the actual object of the ArrayList, not the
> string. Then when the item changes, the ArrayList will reflect the changes.
> But, in order to do this, you must inherit the ArrayList class and write
> your own class which provides methods for ToString (), because this is what
> the listbox will query to get the string to display in the listbox. Include
> any other override functions as needed.

Thank you for your answer Ryan!
But you haven't completely understood my question (perhaps of my
"german" English :-) )
I don't add strings to the listbox, but objects of my own class with an
overridden ToString() function. So the listbox contains references to
the arraylist. If I remove or add an object in the listbox, the object
in the arraylist will be added or removed as well, that's not my problem.
But in order to provide that the listbox contains the same items as the
arraylist every moment, I have to call a function which fills the
arraylist when I for example change the property, used by the ToString()
method.
I need an arraylist, which is automatically updated when I change the
objects.

Thanks,
Michael

Ryan Dawson

unread,
Sep 19, 2002, 8:03:49 PM9/19/02
to
Michael,

I am not sure if there is an elegant solution to your problem. You may
repost your question.

--

Hope this Helps.

Ryan Dawson


"Michael Dengler" <ma...@dengl.com> wrote in message

news:3D89A495...@dengl.com...

0 new messages