CodeSmith Community
Your Code. Your Way. Faster!

Design-time, Drag/Drop Binding for Infragistics UltraGrid?

Latest post 02-05-2007 6:34 PM by Lusid. 5 replies.
  • 02-04-2007 2:02 AM

    • Lusid
    • Not Ranked
    • Joined on 02-04-2007
    • Posts 8
    • Points 130

    Design-time, Drag/Drop Binding for Infragistics UltraGrid?

    I've seen quite a few posts here where people have no problems binding Infragistics controls to their NetTiers layer. I've been able to do this programmatically in the code, but then I lose the design-time capabilities of the UltraGrid designer in a WinForms based application.

    Take for example my normal method of binding the UltraGrid to the old school ADO.net DataSet.

    1. First, I would drag out a TableAdapter, BindingSource, and my shared custom DataSet.
    2. Next, I would bind the binding source to the DataSet along with the DataMember that corresponds to the data I want.
    3. Then, I would drag out an UltraGrid and tell it to bind to the datasource.

    By doing this, the UltraGrid would automatically create the columns at design-time, allowing me to further modify them at design-time. By doing it this way, I didn't have to actually write any code to modify the UltraGrid to get the initial appearance I wanted... it was done at design-time.

    Now, with NetTiers, it seems the part of the above process that is missing is the DataSet component. It seems the only way to do something like this using similar steps as above is if I could drop the TList<whatever> onto the form as a component the same way I do with DataSet. However, I have no way of dragging a generic TList<whatever> object out onto the form canvas unless I create my own component that inherits from it.

    As an experiment, I did the following and it seems to work with the exact functionality I'm looking for. I am just wondering if this functionality is already in NetTiers and I'm just missing it, or if I am going to have to build my own template generator within the NetTiers templates to create a template like this for every Entity that gets created if I want this kind of drag/drop functionality?

    public class CustomerFormComponent : TList<Customer>, IComponent
    {
    private ISite _site;

    public CustomerFormComponent(IContainer container)
    {
      _site =
    null;
      container.Add(
    this);
    }

    #region IComponent Members
    event EventHandler IComponent.Disposed
    {
     
    add { Disposed += value; }
     
    remove { Disposed -= value; }
    }

    ISite IComponent.Site
    {
      get { return _site; }
      set { _site = value; }
    }
    #endregion

    #region IDisposable Members
    void IDisposable.Dispose()
    {
      base.Dispose(true);
    }
    #endregion
    }

    Then, when I drag the component onto the form, it creates this for me in the designer partial code.

    this.customerFormComponent1 = new CustomerFormComponent(this.components);
    this.customerFormComponent1.AllowEdit = true;
    this.customerFormComponent1.AllowNew = true;
    this.customerFormComponent1.AllowRemove = true;
    this.customerFormComponent1.ContainsListCollection = false;
    this.customerFormComponent1.Filter = null;
    this.customerFormComponent1.RaiseListChangedEvents = true;
    this.customerFormComponent1.Site = null;

    And to use it, all I have to do is something like this on form load.

    customerFormComponent1.AddRange(DataRepository.CustomerProvider.GetAll());

    Since the binding source is already bound to the customerFormComponent1 at design-time, and the grid is already bound to the binding source, then this one line of code is all that's needed to fill up that beautiful Infragistics UltraGrid. Anything already in NetTiers that does this?

    • Post Points: 35
  • 02-04-2007 9:43 AM In reply to

    • Faulcon
    • Top 150 Contributor
    • Joined on 12-12-2005
    • Posts 32
    • Points 1,040

    Re: Design-time, Drag/Drop Binding for Infragistics UltraGrid?

    You can use design time databinding in VS2005 with Infragistics and NetTiers by defining an object data source, which you point at the NetTiers entities. Then, from the Infragistics controls, just select the data source you created, instead of dragging in a TableAdapter.

     

    Mark Faulcon

    • Post Points: 35
  • 02-04-2007 8:45 PM In reply to

    • Lusid
    • Not Ranked
    • Joined on 02-04-2007
    • Posts 8
    • Points 130

    Re: Design-time, Drag/Drop Binding for Infragistics UltraGrid?

    Strange. That's what I assumed the correct answer was initially, but it doesn't work. Every time I attempt to connect the UltraGrid to the binding source that is connected to the object data source, it just crashes Visual Studio. Besides, it doesn't make sense to bind directly to the entity. The entity is by definition a single element. Since this is a grid, it only makes sense to connect it to a TList of the entity.

    The only time I can make this work is if I choose a TList collection contained within the entity in the datamember field of the binding source. This makes sense, but it seems silly to use an object data source's relationship collection instead of just using the object itself that I want to use. After doing this several times on a single form, things are going to get confusing.

    There's no way to do this in NetTiers already? Is my suggestion in my first post really the only way I can do this? Because it works perfectly. I just wanted to avoid recreating the wheel... but I guess there is no wheel to recreate.

    Any other suggestions?

    • Post Points: 35
  • 02-05-2007 9:35 AM In reply to

    • GRAW
    • Top 25 Contributor
    • Joined on 06-23-2006
    • Posts 157
    • Points 4,560

    Re: Design-time, Drag/Drop Binding for Infragistics UltraGrid?

    Reply |Contact |Answer

    Well, if you have many to many relationships in your object hierarchy, infragistics designer will crash ur development environment.  The reason for that is that it will go in a recursive loop trying to create "bands" for each child collection it finds, and when you have a many to many relationship, or even some kind of circular reference in your object hierarchy, it will go in a recursive loop and crash ur visual studio.  I've had to deal with this myself.

    The secret (from posts on infragistics support boards) is to set the Maximum Band Depth, or some setting like this, to 1, but you have to do this BEFORE you actually set the datasource.

    I hope this helps. 

    "Small is the number of them that see with their own eyes, and feel with their own hearts" Albert Einstein
    • Post Points: 60
  • 02-05-2007 4:31 PM In reply to

    • Lusid
    • Not Ranked
    • Joined on 02-04-2007
    • Posts 8
    • Points 130

    Re: Design-time, Drag/Drop Binding for Infragistics UltraGrid?

    Wow, I don't know why I didn't consider that as a possibility. It makes sense. I'll have to try it when I get home from work.

    But if this is the case, I guess my next question would be why my component building method above makes it work fine? Essentially, I'm just binding to a TList<something> via a component source on the form that exposes the TList property that I want to bind. I'm able to do that and bind directly to it the same way that I'm wanting without it crashing, and I am pretty sure that it creates all the bands for the current entity's collections without any hiccups... shrug. It's only when I attempt to create an object data source that it goes nuts.

    Anyways, I'll give it another shot tonight and see if setting the band depth to 1 works. Having the bands automatically created is kind of a nice feature that I don't want to get rid of, however... so I might still do the component thing.

    Anyways, I'll post with my results tonight. Thanks GRAW.

    Marc

    • Post Points: 5
  • 02-05-2007 6:34 PM In reply to

    • Lusid
    • Not Ranked
    • Joined on 02-04-2007
    • Posts 8
    • Points 130

    Re: Design-time, Drag/Drop Binding for Infragistics UltraGrid?

    Yep, you're right. It works. I set the UltraGrid.DisplayLayout.MaxBandDepth to 1 before attaching the datasource, and it worked exactly as expected. And I was even happier when I set it to 2 and it added all of my one to many and many to many relationships directly beneath it. Absolutely perfect! :)

    Thanks Graw!

    Marc

    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems