Databinding and ArrayLists

T

Trollpower

Dear NG,

ive got the following problem with databinding, and i hope someone can
help me out there.

Ive a simple form wit a few controls. With the DateTimePicker the user
can choose a date and also a time. If the user clicks on a Button the
choosen Date and Time are put into a ArrayList. I put the ArrayList
into a ListBox to show the choosen date and time.

Now the ListBox sould show the values, but nothing happens. The
following code shows how i use the Databinding:

//Constructorcode

this.dateTimes = new ArrayList();
listBox1.DataSource = this.dateTimes;
listBox1.DisplayMember = "DateTimeString";//DateTimeString is a
formated string of the DateTimeObject-class with additional functions

//Eventmethod of the button
private void button1_Click(object sender, System.EventArgs e)
{
DateTime dateTime = new DateTime(this.m_picker.Value.Year,
this.m_picker.Value.Month,
this.m_picker.Value.Day,
Convert.ToInt32(this.comboBox1.SelectedItem),
Convert.ToInt32(this.comboBox2.SelectedItem),
0);
DateTimeWrapper dtw = new DateTimeWrapper(dateTime);
if(!this.dateTimes.Contains(dtw))
{
dateTimes.Add(dtw);
}
else{
MessageBox.Show("Time allready set!");
}
}

As far as i understand DataBinding, i only have to define a source for
the control, and as soon as the data changes within the source, the
control refreshes its shown values.

Any help on this problem is appreciated.

Thanks in advance

Jens
 
T

Trollpower

Thank you for your answer. DateTimeString is a property of type string.

Greetings

Jens
 
I

Ilya Tumanov [MS]

As you change data in the data source, bound control will be updated, but
only if data source supports update notifications.

ArrayList (which implements IList) does not support notifications, so it's
up to you to update data.

You could extend ArrayList so it would implement IBindingList with
notification support or switch to another data source which supports
notification.


Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 

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