Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Binding to a single entity
 

Pages: 1
LLBLGen Pro Runtime Framework
Binding to a single entity
Page:1/1 

  Print all messages in this thread  
Poster Message
alexdresko
User



Location:
Greenville, SC
Joined on:
08-Jun-2004 17:30:02
Posted:
336 posts
# Posted on: 29-Nov-2004 20:22:20.  
Will it ever be possible to bind a control to a single entity vs an EntityCollection? If not (obviously I haven't tried this yet), should I be able to bind to an EntityCollection for the datasource, and then specify a row index and column name for the datamember?

Thanks!
I'm not a player, I just code a lot.   Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37375 posts
# Posted on: 29-Nov-2004 21:13:45.  
Complex databinding controls require IList implementing datasources. Typically this is true for list-oriented controls like grids, combo-boxes, listboxes etc. etc.

Simple databinding controls like textboxes, require just a property on an object.

So, you can bind an entity collection to a grid, and bind the current entity's properties to textboxes for example.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Andrei
User



Location:

Joined on:
19-Jan-2007 05:04:58
Posted:
7 posts
# Posted on: 08-Mar-2007 04:10:12.  
So, how do you do it? I bound a few text boxes to an entity type (I have AlphaEntity class with LastName, FirstName properties which I bound to those text boxes), then after initialization, I assigned the datasource of my binding source to an acutal entity object. It did not work, here is my code:

            m_AlphaEntity = new AlphaEntity(hAlpha);
            if (m_AlphaEntity.IsNew)
                throw new System.ApplicationException("The hAlphaKey " + hAlpha.ToString() + " not found.");

            // bind the controls on the form:
            this.alphaEntityBindingSource.DataSource = m_AlphaEntity;


            // adding the following code did not help to display the LastName and the FirstName of the current m_AlphaEntity either:
            this.alphaEntityBindingSource.ResetBindings(true);
            this.alphaEntityBindingSource.ResetCurrentItem();
            this.alphaEntityBindingSource.MoveFirst();


// Here is what the designer did inside the InitializeComponent():

            this.alphaEntityBindingSource.DataSource = typeof(Data911.Booking.EntityClasses.AlphaEntity);

            this.lastNameTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.alphaEntityBindingSource, "LastName", true));




Thanks.
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14464 posts
# Posted on: 08-Mar-2007 05:47:00.  
Just try the following:
Code:

m_AlphaEntity = new AlphaEntity(hAlpha);
            if (m_AlphaEntity.IsNew)
                throw new System.ApplicationException("The hAlphaKey " + hAlpha.ToString() + " not found.");

            // bind the controls on the form:
            this.lastNameTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", m_AlphaEntity, "LastName", true));


  Top
Andrei
User



Location:

Joined on:
19-Jan-2007 05:04:58
Posted:
7 posts
# Posted on: 08-Mar-2007 23:20:34.  
Thanks Walaa, although, it does not seem like a perfect solution. You are suggesting to rebind controls every time the object data changes. This is going to affect the performance, not to mention the maintenance issue. What is the binding to type then for? Anyways, I suppose I can change my code to reuse the object, and get the new content using FetchUsingPK method. I have 2 questions in this regard:

1. If I reuse the object using Fetch, will it nullify the related objects that were fetched into the previous instance via navigation?

1. I suppose it is more efficient than creating a new object, by how much? Is there any guidance on one method vs. the other?

Thank you for your help.

  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14464 posts
# Posted on: 09-Mar-2007 08:45:42.  
Quote:
You are suggesting to rebind controls every time the object data changes.

I didn't mean that, just use the TextBox.Databindings.Add() method in the load or initialization of the form.

Quote:
If I reuse the object using Fetch, will it nullify the related objects that were fetched into the previous instance via navigation?

If you have a graph of objects and you re-fetched an object within that graph, only the fetched object will be updated and the rest will be left as is.


  Top
Andrei
User



Location:

Joined on:
19-Jan-2007 05:04:58
Posted:
7 posts
# Posted on: 12-Mar-2007 04:55:00.  
Thanks for your help Walaa. I figured it out. When you bind to a data type, the binding source is still a collection. Here is the way to do it, that works for me (in case someone else runs into the same problem):

             if (this.alphaEntityBindingSource.Count == 0)
                this.alphaEntityBindingSource.Add(m_AlphaEntity);
            else
                this.alphaEntityBindingSource[0] = m_AlphaEntity;


  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14464 posts
# Posted on: 12-Mar-2007 07:30:01.  
Thanks for the feedback

  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.