Data bound DateTimePicker on tab page causes System.ArgumentOutOfRangeException

  • Thread starter Thread starter Michael Kremser
  • Start date Start date
M

Michael Kremser

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]
 
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
 
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
 
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
 
Michael Kremser said:
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
 
Back
Top