Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataBindings.Add();
Message
 
To
17/01/2006 12:53:34
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01087341
Message ID:
01087636
Views:
11
Bonnie,
Yeah I have in the past noticed similar things when I added databindings in the constructor, but that is not the case here. I don't even add the databindings in the Load. I have a separate method in the usercontrol that does the databinding.


>Another thing you can investigate is *where* you're doing the databinding ... in the Constructor or in the Load of the control? I frequently have issues with databinding in the constructor and none when databinding from the load.
>
>And now, I gotta get back to work! =)
>
>~~Bonnie
>
>
>
>>Bonnie,
>>Thanks for the reply, but I don't think it is the enum that is the problem. I have added databindings to several enum based properties in the past. This something really odd (and probably something really silly), but it is really kicking my butt yesterday and today.
>>I started revamping some "old" code to use databindings instead of "hard-coding" the UI in the usercontrols. I set out to do that as a quick project but it turned out to be a little nightmare.
>>
>>I have written several test apps where I was hoping to duplicate the problem on a smaller scale but all my test apps work just fine.
>>
>>deep breath :)
>>
>>
>>
>>>Einar,
>>>
>>>The only thing I can think of right off the top of my head is that it may have something to do with trying to use Enums for databinding ... I've never tried to do that and I don't know *why* it shouldn't work that way, but I don't have time to test it right now. I hate to send you off on a wild goose chase if the Enum has nothing to do with it, but at first glance that's the only thing that jumps out at me. I'll play with it a little more later today, but can't do it right now.
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>Bonnie,
>>>>Here is some "real" code.
>>>>
>>>>Property for the user control (property of this.foTemperature)
>>>>
>>>>[Category("Data")]
>>>>[Description("some description")] //TODO: add a description
>>>>[DefaultValue(ALS.Terminator.Enums.TemperatureGlobal.Cold)]
>>>>[RefreshProperties(RefreshProperties.Repaint)]
>>>>public ALS.Terminator.Enums.TemperatureGlobal GlobalTemperature
>>>>{
>>>>	get
>>>>	{
>>>>		ALS.Terminator.Enums.TemperatureGlobal ReturnValue;
>>>>		if (this.chkGlobalTemperature.Checked)
>>>>		{
>>>>			if (this.rbCold.Checked)
>>>>			{
>>>>				ReturnValue = ALS.Terminator.Enums.TemperatureGlobal.Cold;
>>>>			}
>>>>			else if (this.rbWarm.Checked)
>>>>			{
>>>>				ReturnValue = ALS.Terminator.Enums.TemperatureGlobal.Warm;
>>>>			}
>>>>			else if (this.rbHot.Checked)
>>>>			{
>>>>				ReturnValue = ALS.Terminator.Enums.TemperatureGlobal.Hot;
>>>>			}
>>>>			else
>>>>			{
>>>>				ReturnValue = ALS.Terminator.Enums.TemperatureGlobal.Cold;
>>>>			}
>>>>		}
>>>>		else
>>>>		{
>>>>			ReturnValue = ALS.Terminator.Enums.TemperatureGlobal.NotGlobal;
>>>>		}
>>>>
>>>>		return ReturnValue;
>>>>	}
>>>>	set
>>>>	{
>>>>		switch (value)
>>>>		{
>>>>			case ALS.Terminator.Enums.TemperatureGlobal.Cold:
>>>>				this.chkGlobalTemperature.Checked = true;
>>>>				this.rbCold.Checked = true;
>>>>				break;
>>>>			case ALS.Terminator.Enums.TemperatureGlobal.Warm:
>>>>		                  this.chkGlobalTemperature.Checked = true;
>>>>				this.rbWarm.Checked = true;
>>>>				break;
>>>>			case ALS.Terminator.Enums.TemperatureGlobal.Hot:
>>>>				this.chkGlobalTemperature.Checked = true;
>>>>				this.rbHot.Checked = true;
>>>>				break;
>>>>			case ALS.Terminator.Enums.TemperatureGlobal.NotGlobal:
>>>>				this.chkGlobalTemperature.Checked = false;
>>>>				this.rbCold.Checked = true;
>>>>				break;
>>>>			default:
>>>>				this.chkGlobalTemperature.Checked = true;
>>>>				this.rbCold.Checked = true;
>>>>				value = ALS.Terminator.Enums.TemperatureGlobal.Cold;
>>>>				break;
>>>>		}
>>>>				
>>>>		this.EnableDisableControlControls(this.chkGlobalTemperature.Checked);
>>>>	}
>>>>}
>>>>
>>>>
>>>>
>>>>Property for the object class (property of this.oFill):
>>>>
>>>>public ALS.Terminator.Enums.TemperatureGlobal GlobalTemperature
>>>>{
>>>>	get
>>>>	{
>>>>		return this.globalTemperature;
>>>>	}
>>>>	set
>>>>	{
>>>>		if (Enum.IsDefined(typeof(ALS.Terminator.Enums.TemperatureGlobal), value))
>>>>		{
>>>>			this.globalTemperature = value;
>>>>		}
>>>>		else
>>>>		{
>>>>			throw new ArgumentException("Invalid Fill Step Global Temperature value (" + ((byte) value).ToString()+").");
>>>>		}
>>>>	}
>>>>}
>>>>
>>>>
>>>>And here is the line that fails:
>>>>
>>>>this.foTemperature.DataBindings.Add("GlobalTemperature", this.oFill, "GlobalTemperature");
>>>>
>>>>
>>>>I hope this code explains things better than my previous writing.
>>>>
>>>>Einar
>>>>
>>>>>>(Hmm this doesn't make a lot of sense even if I know what I am talking about <s>)<
>>>>>
>>>>>LOL! Well ... it makes a *little* bit of sense ... maybe. <s>
>>>>>
>>>>>>I'll post some "real" code when I get back to work tomorrow.<
>>>>>
>>>>>OK ... I'll read the "real" code when *I* get back to work tomorrow. =)
>>>>>
>>>>>~~Bonnie
>>>>>
>>>>>
>>>>>>Bonnie,
>>>>>>Thanks for your reply.
>>>>>>1) check
>>>>>>2) check
>>>>>><bg>
>>>>>>I said it is probably something obvious, but not that obvious :)
>>>>>>
>>>>>>The same fooUserControl instance, that I am having a problem databinding, has another property that I databind to a different property in the same fooObject without any problems. (Hmm this doesn't make a lot of sense even if I know what I am talking about <s>)
>>>>>>
>>>>>>I'll post some "real" code when I get back to work tomorrow.
>>>>>>
>>>>>>Einar
>>>>>>
>>>>>>>Einar,
>>>>>>>
>>>>>>>In order for this to work, I think you need the following:
>>>>>>>
>>>>>>>1) "UserControlProperty" has to be a property in the UserControl class from which fooUserControl is instantiated (a real property, with Get/Set methods).
>>>>>>>
>>>>>>>2) "ObjectProperty" has to be a property in the Object class from which fooObject is instantiated (again, a real property).
>>>>>>>
>>>>>>>If you already *do* have it set up like this, how about posting some relevant code?
>>>>>>>
>>>>>>>~~Bonnie
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>I am having some problems adding a databinding to my object. The following line throws an exception:
>>>>>>>>
>>>>>>>>this.fooUserControl.DataBindings.Add("UserControlProperty", this.fooObject, "ObjectProperty");
>>>>>>>>
>>>>>>>>
>>>>>>>>The exception caught is:
>>>>>>>>
>>>>>>>>System.ArgumentException: Object type cannot be converted to target type.
>>>>>>>>
>>>>>>>>
>>>>>>>>I can't figure out why the exception is thrown. I am sure I am overlooking something very obvious.
>>>>>>>>
>>>>>>>>Any help would be appreciated.
>>>>>>>>
>>>>>>>>Thanks,
>>>>>>>>Einar
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform