PC Review


Reply
Thread Tools Rate Thread

Databinding and ArrayLists

 
 
Trollpower
Guest
Posts: n/a
 
      6th Jun 2005
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWxleCBZYWtobmluIFtNVlBd?=
Guest
Posts: n/a
 
      6th Jun 2005
DateTimeString is a property or a field?

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


"Trollpower" wrote:

> 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
>
>

 
Reply With Quote
 
Trollpower
Guest
Posts: n/a
 
      6th Jun 2005
Thank you for your answer. DateTimeString is a property of type string.

Greetings

Jens

 
Reply With Quote
 
Ilya Tumanov [MS]
Guest
Posts: n/a
 
      6th Jun 2005
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/...ramework?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).

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



 
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
Databinding expressions are only supported on objects that have a DataBinding event jobs Microsoft ASP .NET 0 26th Sep 2007 12:54 AM
Sorting & ArrayLists MikeY Microsoft C# .NET 5 26th Jan 2006 07:16 PM
Sockets and ArrayLists Adrian McNally Microsoft C# .NET 0 13th Nov 2005 02:23 AM
Databinding Bible (REPOST FROM m.p.d.f.WindowsForms.Databinding) a Microsoft ADO .NET 1 16th Jul 2004 03:26 AM
ArrayLists =?Utf-8?B?SGkgSQ==?= Microsoft Dot NET 3 2nd Mar 2004 06:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:05 PM.