"strongly typed" databinding option?

Posts   
 
    
caseyry
User
Posts: 79
Joined: 25-Feb-2005
# Posted on: 27-Nov-2006 23:38:59   

[This doesn't relate specifically to LLBLGen, but more to the .Net framework in general.]

For this project, we're currently using:

.Net 1.1 (C#) LLBLGen 1.2005.1

I've seen general databinding examples that do something like this:


ucbPressProgram.DataBindings.Add(new Binding("Value", this.objPressWhiteBiz, "PressProgramId"));

where objPressWhiteBiz is a biz object we wrote and ucbPressProgram is an Infragistics UltraComboBox.

Is there a way to avoid "hard coding" the property of the biz object? I.e. doing something like this:


ucbPressProgram.DataBindings.Add(new Binding("Value", this.objPressWhiteBiz, objPressWhiteBiz.PressProgramId));

I've searched the web and looked at various documents on databinding, and all seem to point to using strings for the object's property.

If .Net 1.x doesn't offer this, does .Net 2.0? From what I could tell, the new "BindingSource" control and VS.Net wizards just generate the mappings in the .designer.cs file using the same method as my first code example.

Thanks for any input or suggestions.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 28-Nov-2006 03:10:04   

I know this isn't an LLBLGen question, but if you are using an LLBLGenEntity then you can use an IEntityField's Name property to retrieve something similar. You may implement something like this for your object's properties that will be databound.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 28-Nov-2006 11:08:14   

Some people use things like CustomerFieldIndex.CustomerId.ToString() which prints "CustomerId", and is compile time checked.

Frans Bouma | Lead developer LLBLGen Pro
caseyry
User
Posts: 79
Joined: 25-Feb-2005
# Posted on: 28-Nov-2006 15:40:40   

Thanks, I appreciate the suggestions.

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 29-Nov-2006 19:46:28   

Follow up question smile

We place controls on our form with the VS2005 forms designer, and type in the property name into a datamember field in the "Properties" window for the control. Is there any way to get this field to display a dropdown of all fields of an entity type which is defined in another property?

I can't think of a way to do this other than to generate EntityName+EntityFieldName combinations into a custom enumeration...any suggestions?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Nov-2006 10:25:09   

(please: next time don't hijack a thread, start a new one. Your question has nothing to do with the original question of this thread)

I'm not exactly sure what you mean, but property grids work with reflection, so if there's no property in the bound object which returns an enum with the names, you won't be able to set it. So indeed you need to add it with a custom enum.

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 30-Nov-2006 17:15:38   

Otis wrote:

(please: next time don't hijack a thread, start a new one. Your question has nothing to do with the original question of this thread)

I'm not exactly sure what you mean, but property grids work with reflection, so if there's no property in the bound object which returns an enum with the names, you won't be able to set it. So indeed you need to add it with a custom enum.

confused

You answered his databinding property question by suggesting he use the EntityFieldIndex enumeration. I asked if there was a way to combine the Entity enum (dropdown in property window) with the EntityFieldIndex (another dropdown) to do databinding.

I suppose I should have been more clear that I was talking about using the EntityFieldIndex for databinding, but whatever.

Anyways, thanks for the answer. I was hoping there was some crazy use of generics that I was unaware of to make a property return a specific type of enumeration based on another factor (like the EntityEnum).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 30-Nov-2006 18:21:01   

mikeg22 wrote:

Otis wrote:

(please: next time don't hijack a thread, start a new one. Your question has nothing to do with the original question of this thread)

I'm not exactly sure what you mean, but property grids work with reflection, so if there's no property in the bound object which returns an enum with the names, you won't be able to set it. So indeed you need to add it with a custom enum.

confused

You answered his databinding property question by suggesting he use the EntityFieldIndex enumeration. I asked if there was a way to combine the Entity enum (dropdown in property window) with the EntityFieldIndex (another dropdown) to do databinding.

I suppose I should have been more clear that I was talking about using the EntityFieldIndex for databinding, but whatever.

This is exactly the reason why we ask users of this forum not to hijack threads to post questions which to them seem similar to the topic discussed but for us that's not always clear: should we re-read the whole thread and use that info with your question, or is your question simply new? That's why we ask users to open a NEW thread instead.

Anyways, thanks for the answer. I was hoping there was some crazy use of generics that I was unaware of to make a property return a specific type of enumeration based on another factor (like the EntityEnum).

You could cheat. There are a couple of ways to add an 'editor' for a property so when that property is shown in the propertygrid, the editor is used. It's documented in the MSDN docs, though it's pretty advanced and I'm not sure it will lead to results you can use. But it's worth a try. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 30-Nov-2006 18:35:43   

Otis wrote:

mikeg22 wrote:

Otis wrote:

(please: next time don't hijack a thread, start a new one. Your question has nothing to do with the original question of this thread)

I'm not exactly sure what you mean, but property grids work with reflection, so if there's no property in the bound object which returns an enum with the names, you won't be able to set it. So indeed you need to add it with a custom enum.

confused

You answered his databinding property question by suggesting he use the EntityFieldIndex enumeration. I asked if there was a way to combine the Entity enum (dropdown in property window) with the EntityFieldIndex (another dropdown) to do databinding.

I suppose I should have been more clear that I was talking about using the EntityFieldIndex for databinding, but whatever.

This is exactly the reason why we ask users of this forum not to hijack threads to post questions which to them seem similar to the topic discussed but for us that's not always clear: should we re-read the whole thread and use that info with your question, or is your question simply new? That's why we ask users to open a NEW thread instead.

Anyways, thanks for the answer. I was hoping there was some crazy use of generics that I was unaware of to make a property return a specific type of enumeration based on another factor (like the EntityEnum).

You could cheat. There are a couple of ways to add an 'editor' for a property so when that property is shown in the propertygrid, the editor is used. It's documented in the MSDN docs, though it's pretty advanced and I'm not sure it will lead to results you can use. But it's worth a try. simple_smile

Point taken about the new thread. I thought the answer to my question might be useful for people wanting advice on how to databind to an entity property, but it was a bit unrelated from the original question.

I'll look into the use of editors. simple_smile