entity framework 5 - DatePicker.Value.Set Error binding to datasource -


i have bindingsource control called binding, on form in vs2012, , datetimepicker control bound it.

for binding properties have mindate = 1/01/1753 , maxdate = 31/12/9998 value has been set picking today calender 5/04/2013 11:27 am

i set bindingsource using

var dset = base.context.contactevents; var qry = dset.where(p => p.id > 0).orderby(x => x.id); qry.load(); this.bindingsource.datasource = dset.local.tobindinglist(); 

the bindingsource used in following manner;

 public void refreshbindingdatasourceandposition(bindingsource binding)   {     binding.datasource = this.bindingsource.datasource;  // error raised here     binding.position = this.bindingsource.position;   } 

the error information

system.argumentoutofrangeexception crossed native/managed boundary hresult=-2146233086 message=value of '1/01/0001 12:00:00 am' not valid 'value'. 'value' should between 'mindate' , 'maxdate'. parameter name: value source=system.windows.forms paramname=value stacktrace: @ system.windows.forms.datetimepicker.set_value(datetime value) innerexception:

i can work around problem not binding data picker , , setting in eventsbindingsource_currentchanged event

however seems odd have this. how can databinding working?

[update] problem similar 1 described here have tried reproduce problem in simpler project try , isolate cause, works in simpler project. project works on computer. problem occurs on computer both sql server 2012 , 2008r2. have tried altering date format , country in control panel. have tried different settings format property. have tried setting date field support null.

when copy error clipboard shows following ;

system.reflection.targetinvocationexception occurred hresult=-2146232828 message=exception has been thrown target of invocation. source=mscorlib stacktrace: @ system.runtimemethodhandle.invokemethod(object target, object[] arguments, signature sig, boolean constructor) @ system.reflection.runtimemethodinfo.unsafeinvokeinternal(object obj, object[] parameters, object[] arguments) innerexception: system.argumentoutofrangeexception hresult=-2146233086 message=value of '1/01/0001 12:00:00 am' not valid 'value'. 'value' should between 'mindate' , 'maxdate'. parameter name: value source=system.windows.forms paramname=value stacktrace: @ system.windows.forms.datetimepicker.set_value(datetime value) innerexception:

my ef class follows

public class contactevent : loggedentity {      public virtual sortablebindinglist<contacteventattendee> attendees { get; private set; }     public virtual contacteventtype contacteventtype { get; set; }     public string details { get; set; }     public datetime? eventtime { get; set; }     public virtual sortablebindinglist<contacteventitem> items { get; private set; }     public int state { get; set; }     public string title { get; set; }     public override string tostring()     {         return "contact events";     } } 

it inherits

public abstract class loggedentity {     public loggedentity()     {         this.rowid = guid.newguid();         this.rowversionid = 0;         appdomain dm = appdomain.currentdomain;  // gets current application domain current thread.         object s = appdomain.currentdomain.getdata("sitenumber");         this.sourcesitenumber = convert.toint32(s);     }      public loggedentity(int sitenumber)     {         // following 3 used identify version          this.rowid = guid.newguid();         this.rowversionid = 0;         this.sourcesitenumber = sitenumber;     }      public int id { get; set; }     public guid rowid { get; set; }      [concurrencycheck]     public int rowversionid { get; set; }     public int sourcesitenumber { get; set; }  } 

[update] similar problem here

[update] here makes me think need @ how keys being processed.

[update] noticed following in output window

a first chance exception of type 'system.argumentoutofrangeexception' occurred in system.windows.forms.dll 

[update] led me here

and after turning on debug options found error

invalid object name 'dbo.__migrationhistory'. 

however known bug in ef5

[update]: found person similar unsolved issues here discovered dont have problems when running .exe

[update] can skip on error disabling "break when exceptions cross app domain or managed/native boundary in tools->options->debugging->general

[update] adding following, inspect control properties.

    private void eventsbindingsource_bindingcomplete(object sender, bindingcompleteeventargs e)     {         // if bindingcomplete state other success,          // set errorprovider error message.         if (e.bindingcompletestate != bindingcompletestate.success)         {             errorprovider1.seterror((control)e.binding.bindablecomponent, e.errortext);             var errdesc = e.errortext;             var ctrl = (control)e.binding.bindablecomponent;               var info = string.format(                "{0} {1}",errdesc,                ctrl.tostring());              debug.print(info);             // "value of '1/1/0001 12:00:00 am' not valid 'value'.               'value' should between 'mindate' , 'maxdate'.\r\nparameter name:               value system.windows.forms.datetimepicker, value: 1/1/1900 12:00:00 am"          }         else         {             errorprovider1.seterror((control)e.binding.bindablecomponent, "");         }     } 

the cause of exception may datepicker's databinding "value" property has been set bindingsource field. datepicker's databinding "text" property needs set data binding work correctly. check if there value in datepicker's databinding "value" property field, once removed issue should go away.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -