PC Review


Reply
Thread Tools Rate Thread

Data bound DateTimePicker on tab page causes System.ArgumentOutOfRangeException

 
 
Michael Kremser
Guest
Posts: n/a
 
      10th Mar 2009
Hi NG!

If I put a DateTimePicker on a tab page and bind it to data and use a
BindingNavigator and BindingSource to navigate, the application throws
an System.ArgumentOutOfRangeException exception unless I click the tab
the DateTimePicker lies on.

Does anyone know the reason for that and some better workaround than
showing the tab page at start up (like tabControl1.SelectedIndex = 1?

To demonstrate this, I made a small test application [1].

Any ideas greatly appraciated.

Greetings,

Michael

[1] http://temp.mkcs.at/windoze/DateTimePickerDataTest.zip [50 KiB]
 
Reply With Quote
 
 
 
 
Dawid Rutyna
Guest
Posts: n/a
 
      14th Mar 2009
> Does anyone know the reason for that and some better workaround than
> showing the tab page at start up (like tabControl1.SelectedIndex = 1?


Try this:

dtX = new DataTable("Test data");
dtX.Columns.Add("Name", typeof(string));
dtX.Columns.Add("Day", typeof(DateTime));
dtX.Rows.Add("Austria", new DateTime(2009, 3, 10));
dtX.Rows.Add("Germany", new DateTime(2006, 7, 15));
dtX.Rows.Add("Belarus", new DateTime(2005, 5, 31));
dtX.Rows.Add("Poland", new DateTime(1985, 10, 15));
bindingSource1.DataSource = dtX;

txtName.DataBindings.Add("Text", bindingSource1, "Name");
dateTimePicker1.DataBindings.Add("Text", bindingSource1, "Day");

Dawid Rutyna


 
Reply With Quote
 
Michael Kremser
Guest
Posts: n/a
 
      16th Mar 2009
On 14 Mrz., 16:33, "Dawid Rutyna" <ruty...@gmail.com> wrote:
> > Does anyone know the reason for that and some better workaround than
> > showing the tab page at start up (like tabControl1.SelectedIndex = 1?

>
> Try this:
>
> dtX = new DataTable("Test data");
> dtX.Columns.Add("Name", typeof(string));
> dtX.Columns.Add("Day", typeof(DateTime));
> dtX.Rows.Add("Austria", new DateTime(2009, 3, 10));
> dtX.Rows.Add("Germany", new DateTime(2006, 7, 15));
> dtX.Rows.Add("Belarus", new DateTime(2005, 5, 31));
> dtX.Rows.Add("Poland", new DateTime(1985, 10, 15));
> bindingSource1.DataSource = dtX;
>
> txtName.DataBindings.Add("Text", bindingSource1, "Name");
> dateTimePicker1.DataBindings.Add("Text", bindingSource1, "Day");
>
> Dawid Rutyna


As far as I can see, that's exactly the same code that I wrote (just
without the item "Poland" - which doesn't make a difference, of
course). What would you like to tell me with that?

Regards,

Michael
 
Reply With Quote
 
Michael Kremser
Guest
Posts: n/a
 
      16th Mar 2009
On 10 Mrz., 22:38, Michael Kremser <mkspamx-use...@yahoo.de> wrote:
> Hi NG!
>
> If I put a DateTimePicker on a tab page and bind it to data and use a
> BindingNavigator and BindingSource to navigate, the application throws
> an System.ArgumentOutOfRangeException exception unless I click the tab
> the DateTimePicker lies on.
>
> Does anyone know the reason for that and some better workaround than
> showing the tab page at start up (like tabControl1.SelectedIndex = 1?
>
> To demonstrate this, I made a small test application [1].
>
> Any ideas greatly appraciated.
>
> Greetings,
>
> Michael
>
> [1]http://temp.mkcs.at/windoze/DateTimePickerDataTest.zip[50 KiB]


I found a workaround for this myself. I do not yet understand the real
problem, but there are two facts:

* If I put my data binding code into the "Load" event (instead of the
contructor of the form), it suddenly works.
* If I query the "Handle" property - no matter if I do that before or
after binding -, it stops working!

It still does not work to query the value of a control that hasn't
been shown already (empty string in "Text" property of a TextBox,
DateTime.Now in "Value" property of a DateTimePicker).
"dateTimePicker1.DataBindings[0].ReadValue()" throws the same
"System.ArgumentOutOfRangeException" exception as I had before.

Any suggestions are still appreciated.

Best regards,

Michael
 
Reply With Quote
 
Dawid Rutyna
Guest
Posts: n/a
 
      16th Mar 2009

"Michael Kremser" <(E-Mail Removed)> wrote in message
news:94de68f9-78dc-4dfe-a21e-(E-Mail Removed)...
> On 14 Mrz., 16:33, "Dawid Rutyna" <ruty...@gmail.com> wrote:
>> > Does anyone know the reason for that and some better workaround than
>> > showing the tab page at start up (like tabControl1.SelectedIndex = 1?

>>
>> Try this:
>>
>> dtX = new DataTable("Test data");
>> dtX.Columns.Add("Name", typeof(string));
>> dtX.Columns.Add("Day", typeof(DateTime));
>> dtX.Rows.Add("Austria", new DateTime(2009, 3, 10));
>> dtX.Rows.Add("Germany", new DateTime(2006, 7, 15));
>> dtX.Rows.Add("Belarus", new DateTime(2005, 5, 31));
>> dtX.Rows.Add("Poland", new DateTime(1985, 10, 15));
>> bindingSource1.DataSource = dtX;
>>
>> txtName.DataBindings.Add("Text", bindingSource1, "Name");
>> dateTimePicker1.DataBindings.Add("Text", bindingSource1, "Day");
>>
>> Dawid Rutyna

>
> As far as I can see, that's exactly the same code that I wrote (just
> without the item "Poland" - which doesn't make a difference, of
> course).


No, it is not.

>What would you like to tell me with that?


That I am from Poland :-).

Dawid Rutyna


 
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
System.ArgumentOutOfRangeException =?Utf-8?B?S3Jpc2huYQ==?= Microsoft ADO .NET 2 20th Sep 2006 02:06 AM
System.ArgumentOutOfRangeException occurred in system.windows.forms.dll Martin Henke Microsoft VB .NET 0 16th Jun 2006 03:44 PM
System.ArgumentOutOfRangeException: Index was out of range hari Microsoft ASP .NET 2 19th Nov 2004 09:37 PM
Help - System.Data.DataTable.InsertRow() throws ArgumentOutOfRangeException Jim Meehan Microsoft ADO .NET 4 9th Mar 2004 04:18 PM
BindingContext.AddNew method does not work if a DateTimePicker has been data bound Joshua Ellul Microsoft ADO .NET 6 19th Oct 2003 10:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:16 AM.