- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Child Collections: MappingName and TableStyles for a DataGrid
Joined: 30-Mar-2005
I have searched for and reviewed the responses for similar issues, but I haven't seen anything directly related to this situation.
Scenario: I have a DT collection dragged onto a form. I set the DataSource of my grid to a CHILD collection off of that collection. I cannot get the tablestyles to map properly. I have trying putting in the child collection type, the child collection entity type name, the child property name.
It works fine if I set the DataSource to the root design time collection and set the MappingName of my TableStyle to "root collection type name."
Any thoughts?
EdDotNet wrote:
I have searched for and reviewed the responses for similar issues, but I haven't seen anything directly related to this situation.
Scenario: I have a DT collection dragged onto a form. I set the DataSource of my grid to a CHILD collection off of that collection. I cannot get the tablestyles to map properly. I have trying putting in the child collection type, the child collection entity type name, the child property name.
Aren't the columns defined for that child collection automatically? As in: if you drag a customer collection onto the form, you can set the grid to the Orders collection and hte columns should show up.
Joined: 30-Mar-2005
Otis wrote:
EdDotNet wrote:
I have searched for and reviewed the responses for similar issues, but I haven't seen anything directly related to this situation.
Scenario: I have a DT collection dragged onto a form. I set the DataSource of my grid to a CHILD collection off of that collection. I cannot get the tablestyles to map properly. I have trying putting in the child collection type, the child collection entity type name, the child property name.
Aren't the columns defined for that child collection automatically? As in: if you drag a customer collection onto the form, you can set the grid to the Orders collection and hte columns should show up.
The default columns DO show up, but it shows EVERY column. Naturally, I want to customize the display of columns on the grid. I want to set a TableStyle for that particular collection (using MappingName) but no matter what I've tried it doesn't work.
It only works if the collection I am binding the grid to is the root or top most collection. In that case, as you've suggested in another post, I use "Collection Type Name" as my MappingName in my TableStyle. ie. "MappingName = MyEntityCollectionName"
EdDotNet wrote:
Otis wrote:
What's the grid you're using, infragistics?
No, the standard Microsoft DataGrid.
then you shouldn't see all columns, but just the ones you designed. Weird.
We are actually in the market for some third-party controls. Can you recommend any that work well with LLBLGen?
The current, very latest release of infragistics seems to work ok, though I always recommend Janus Systems stuff (http://www.janusys.com) as they're very responsive in support, the controls have great quality and fully support .NET standards. (so no 'dataset only' crap)
Joined: 30-Mar-2005
Otis wrote:
EdDotNet wrote:
Otis wrote:
What's the grid you're using, infragistics?
No, the standard Microsoft DataGrid.
then you shouldn't see all columns, but just the ones you designed. Weird.
We are actually in the market for some third-party controls. Can you recommend any that work well with LLBLGen?
The current, very latest release of infragistics seems to work ok, though I always recommend Janus Systems stuff (http://www.janusys.com) as they're very responsive in support, the controls have great quality and fully support .NET standards. (so no 'dataset only' crap)
Ok I will check them out. Any insight on the child collection issue with the standard datagrid though?
EdDotNet wrote:
Otis wrote:
EdDotNet wrote:
Otis wrote:
What's the grid you're using, infragistics?
No, the standard Microsoft DataGrid.
then you shouldn't see all columns, but just the ones you designed. Weird.
We are actually in the market for some third-party controls. Can you recommend any that work well with LLBLGen?
The current, very latest release of infragistics seems to work ok, though I always recommend Janus Systems stuff (http://www.janusys.com) as they're very responsive in support, the controls have great quality and fully support .NET standards. (so no 'dataset only' crap)
Ok I will check them out. Any insight on the child collection issue with the standard datagrid though?
If you've set it up using design time databinding, i.e. dragged a collection onto the form, and designed the columns, it should just load the data in the columns designed. I can't reproduce the problem you have with that setup, as when I do that I get the columns designed but not other columns. Infragistics grids (older version) show all columns, always, thats why I asked.
If you've setup the grid formatting differently, please say so, as my experience is that if you defined table styles in code, it depends on where you define them (i.e.: call the code which sets them up) to have them have any effect at runtime...
Joined: 30-Mar-2005
Otis wrote:
EdDotNet wrote:
Otis wrote:
EdDotNet wrote:
Otis wrote:
What's the grid you're using, infragistics?
No, the standard Microsoft DataGrid.
then you shouldn't see all columns, but just the ones you designed. Weird.
We are actually in the market for some third-party controls. Can you recommend any that work well with LLBLGen?
The current, very latest release of infragistics seems to work ok, though I always recommend Janus Systems stuff (http://www.janusys.com) as they're very responsive in support, the controls have great quality and fully support .NET standards. (so no 'dataset only' crap)
Ok I will check them out. Any insight on the child collection issue with the standard datagrid though?
If you've set it up using design time databinding, i.e. dragged a collection onto the form, and designed the columns, it should just load the data in the columns designed. I can't reproduce the problem you have with that setup, as when I do that I get the columns designed but not other columns. Infragistics grids (older version) show all columns, always, thats why I asked.
If you've setup the grid formatting differently, please say so, as my experience is that if you defined table styles in code, it depends on where you define them (i.e.: call the code which sets them up) to have them have any effect at runtime...
To be clear, it loads the data fine. What it doesn't do is format the tables per the TableStyle I have mapped to the child collection via "MappingName." I have seen other posts on this topic so I know that you've seen some similar issues to this.
To recreate: -Drag a design-time collection onto a form with a DataGrid. Make sure the collection you drag on has a child relation to a collection.
-Set the DataSource to the collection.
-Set the member to the child collection.
-Create a tablestyle, try various Mapping Names, none of them will work (it will only show the default of ALL columns in the grid).
Joined: 30-Mar-2005
Otis wrote:
Ok, found it.
Set the MappingName to the type name of the collection, so if you're binding CustomerCollection.Orders, you should set the mapping name to OrderCollection.
Ok I'll try it!
BTW - We bought your product, based mostly on your excellent responsiveness and support. Thank you for providing such a great tool.
Joined: 30-Mar-2005
Otis wrote:
Ok, found it.
Set the MappingName to the type name of the collection, so if you're binding CustomerCollection.Orders, you should set the mapping name to OrderCollection.
I tried it, doesn't help.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using CI.ContentManagement.Services;
namespace CI.ContentManagement.AdBanners.WinApp.MDIForms
{
/// <summary>
/// Summary description for Campaigns.
/// </summary>
public class Campaigns : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn4;
private System.Windows.Forms.DataGridBoolColumn dataGridBoolColumn1;
private System.Windows.Forms.Label label1;
private CI.ContentManagement.Data.CollectionClasses.AdClientCompanyCollection adClientCompanyCollection1;
private System.Windows.Forms.ComboBox comboBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.Button btnClose;
protected AdManager adManager;
public Campaigns()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Campaigns));
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn4 = new System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridBoolColumn1 = new System.Windows.Forms.DataGridBoolColumn();
this.label1 = new System.Windows.Forms.Label();
this.adClientCompanyCollection1 = new CI.ContentManagement.Data.CollectionClasses.AdClientCompanyCollection();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.btnSave = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.AllowNavigation = false;
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "AdCampaign";
this.dataGrid1.DataSource = this.adClientCompanyCollection1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 64);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.RowHeadersVisible = false;
this.dataGrid1.Size = new System.Drawing.Size(584, 248);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTableStyle1});
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn1,
this.dataGridTextBoxColumn2,
this.dataGridTextBoxColumn3,
this.dataGridTextBoxColumn4,
this.dataGridBoolColumn1});
this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle1.MappingName = "AdCampaignCollection";
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "Campaign Name";
this.dataGridTextBoxColumn1.MappingName = "AdCampaignCollection.CampaignName";
this.dataGridTextBoxColumn1.Width = 150;
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.Format = "";
this.dataGridTextBoxColumn2.FormatInfo = null;
this.dataGridTextBoxColumn2.HeaderText = "Start Date";
this.dataGridTextBoxColumn2.MappingName = "StartDate";
this.dataGridTextBoxColumn2.Width = 75;
//
// dataGridTextBoxColumn3
//
this.dataGridTextBoxColumn3.Format = "";
this.dataGridTextBoxColumn3.FormatInfo = null;
this.dataGridTextBoxColumn3.HeaderText = "End Date";
this.dataGridTextBoxColumn3.MappingName = "EndDate";
this.dataGridTextBoxColumn3.Width = 75;
//
// dataGridTextBoxColumn4
//
this.dataGridTextBoxColumn4.Format = "";
this.dataGridTextBoxColumn4.FormatInfo = null;
this.dataGridTextBoxColumn4.HeaderText = "Biospace Contact";
this.dataGridTextBoxColumn4.MappingName = "BiospaceContact";
this.dataGridTextBoxColumn4.Width = 150;
//
// dataGridBoolColumn1
//
this.dataGridBoolColumn1.AllowNull = false;
this.dataGridBoolColumn1.FalseValue = false;
this.dataGridBoolColumn1.HeaderText = "Is Active?";
this.dataGridBoolColumn1.MappingName = "IsActive";
this.dataGridBoolColumn1.NullValue = ((object)(resources.GetObject("dataGridBoolColumn1.NullValue")));
this.dataGridBoolColumn1.TrueValue = true;
this.dataGridBoolColumn1.Width = 75;
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Choose Client:";
//
// adClientCompanyCollection1
//
this.adClientCompanyCollection1.AllowEdit = true;
this.adClientCompanyCollection1.AllowNew = true;
this.adClientCompanyCollection1.AllowRemove = false;
this.adClientCompanyCollection1.EntityFactoryToUse = new CI.ContentManagement.Data.FactoryClasses.AdClientCompanyEntityFactory();
this.adClientCompanyCollection1.MaxNumberOfItemsToReturn = ((long)(0));
this.adClientCompanyCollection1.SortClauses = null;
this.adClientCompanyCollection1.SupportsSorting = false;
this.adClientCompanyCollection1.SuppressClearInGetMulti = false;
this.adClientCompanyCollection1.Transaction = null;
this.adClientCompanyCollection1.ValidatorToUse = null;
//
// comboBox1
//
this.comboBox1.DataSource = this.adClientCompanyCollection1;
this.comboBox1.DisplayMember = "CompanyName";
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Location = new System.Drawing.Point(96, 32);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(368, 21);
this.comboBox1.TabIndex = 2;
this.comboBox1.ValueMember = "ClientCompanyId";
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(392, 344);
this.btnSave.Name = "btnSave";
this.btnSave.TabIndex = 3;
this.btnSave.Text = "Save";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(512, 344);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 4;
this.btnClose.Text = "Close";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// Campaigns
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(600, 397);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Campaigns";
this.Text = "Campaigns";
this.Load += new System.EventHandler(this.Campaigns_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void Campaigns_Load(object sender, System.EventArgs e)
{
adManager = new AdManager();
adClientCompanyCollection1 = adManager.GetAllClientCompanies();
comboBox1.DataSource = adClientCompanyCollection1;
//adCampaignCollection1 = adClientCompanyCollection1[ int.Parse( comboBox1.SelectedValue.ToString() ) ].AdCampaign;
//dataGrid1.SetDataBinding( adClientCompanyCollection1, "AdCampaign" );
}
private void bindCampaignGrid ( int clientCompanyId )
{
//adCampaignCollection1 = adClientCompanyCollection1[ clientCompanyId ].AdCampaign;
// dataGrid1.DataSource = adCampaignCollection1;
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
// bindCampaignGrid( int.Parse( comboBox1.SelectedValue.ToString() ) );
}
private void btnSave_Click(object sender, System.EventArgs e)
{
//adCampaignCollection1.SaveMulti( false );
}
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
A tablestyle will be selected if teh collection bound (listname) has the same name as the tablestyle's mappingname.
your table style's mapping name is: AdCampaignCollection you bind another collection: this.dataGrid1.DataSource = this.adClientCompanyCollection1;
Joined: 30-Mar-2005
Otis wrote:
A tablestyle will be selected if teh collection bound (listname) has the same name as the tablestyle's mappingname.
your table style's mapping name is: AdCampaignCollection you bind another collection: this.dataGrid1.DataSource = this.adClientCompanyCollection1;
So what should I specifically do in the designer to get this to work right? Remember, all of this is design-time generated code.
Joined: 30-Mar-2005
Otis wrote:
Use as mapping name in the table style: AdClientCompanyCollection
AdClientCompanyCollection is the PARENT collection. AdCampaignCollection is the CHILD collection I want to bind to. I looked at my code up there, it looks like I copied a version that I was playing with. Trust me, this doesn't work. I will put up more code later if you can't figure it out.
1) Create form 2) Add a combobox 3) Add a datagrid 4) Add a design-time collection that has child collections. 5) In the designer, bind your combobox to the parent. 6) In the designer, bind your datagrid to a child collection of the parent. 7) Try to create table styles for the datagrid.
You know, I DID get it working, but it fails now here too... I can't understand it... the tablestyle should just be selected... Perhaps I miss something with the grid setup...
OK!
I'll use the setup I used here, which is similar to yours. This way I won't mix up names in your setup causing more confusion.
I used a CustomerCollection. (Using northwind). Customer 1:n Order
I dragged the customercollection onto the form. Bound it to both the grid and the combo box. Combobox display member: customerid. Datamember: nothing. Grid datamember: Orders
Now, I created a table style for Order: CustomerId, OrderId and OrderDate. As MappingName for the table style I used: CustomerCollection. As that's the name of the collection bound to the grid.
Simply select the columns in the table style from the drop down and you're set. This does work here, and the key was that I specified the name of the collection set to DataSource as the MappingName.
Joined: 30-Mar-2005
Otis wrote:
OK!
![]()
I'll use the setup I used here, which is similar to yours. This way I won't mix up names in your setup causing more confusion.
I used a CustomerCollection. (Using northwind). Customer 1:n Order
I dragged the customercollection onto the form. Bound it to both the grid and the combo box. Combobox display member: customerid. Datamember: nothing. Grid datamember: Orders
Now, I created a table style for Order: CustomerId, OrderId and OrderDate. As MappingName for the table style I used: CustomerCollection. As that's the name of the collection bound to the grid.
Simply select the columns in the table style from the drop down and you're set. This does work here, and the key was that I specified the name of the collection set to DataSource as the MappingName.
Thanks Otis, I'll try that.
Joined: 29-Apr-2005
Hey Ed and Otis,
I'm right there with you finding this same problem. To expand on the last couple posts, I have basicallly the same setup (master/detail grids). Mine are for Customers and Orders (think Northwind). I couldnt figure out how to get the tablestyle to be applied until I read your posts.
The only way I could get the tablestyles to be applied was by using the collection type of the parent collection (CustomerCollection) as the mapping name for BOTH the parent and child grids. Granted, it would be logical if the tablestyle for the child grid was applied using 'OrderCollection' as the mapping name, but it worked nonetheless.
Interestingly, I added a third datagrid on a hunch, and it behaves the same. In order to get the 3rd datagrid's tablestyle to be applied, you need to use the parent's parent's collection type name, 'CustomerCollection'.
This would be fine except that for design time support, it's limited. For example, when you edit the columnstyles collection for a tablestyle on the 3rd grid, you cant even see the names of the related fields in the designer, but if you type the name of a valid field of the 3rd collection, it will map properly.
Otis, can you reproduce this and give a work-around?
btw, I just discovered this tool yesterday and am already kicking myself for not finding it 10 projects ago
Thanks for the great tool, I will be buying the full version after a little test project with it.
Jim wrote:
Hey Ed and Otis,
I'm right there with you finding this same problem. To expand on the last couple posts, I have basicallly the same setup (master/detail grids). Mine are for Customers and Orders (think Northwind). I couldnt figure out how to get the tablestyle to be applied until I read your posts.
The only way I could get the tablestyles to be applied was by using the collection type of the parent collection (CustomerCollection) as the mapping name for BOTH the parent and child grids. Granted, it would be logical if the tablestyle for the child grid was applied using 'OrderCollection' as the mapping name, but it worked nonetheless.
Interestingly, I added a third datagrid on a hunch, and it behaves the same. In order to get the 3rd datagrid's tablestyle to be applied, you need to use the parent's parent's collection type name, 'CustomerCollection'.
This would be fine except that for design time support, it's limited. For example, when you edit the columnstyles collection for a tablestyle on the 3rd grid, you cant even see the names of the related fields in the designer, but if you type the name of a valid field of the 3rd collection, it will map properly.
I know it's limited but it's unfortunately not my call . The .NET grid IS pretty limited, in that it checks the name of the ITypedList implementing object bound to it with DataSource.
What causes the confusion is that the 'DataMember' at runtime makes the grid contain other data, namely a child collection.
If there is one thing I'd completely re-do in .NET it's databinding, though that's up to MS and all we can do is look at the sideline hoping the stuff they cook up is workable. Up till now (including whidbey) it's... well, sad.
btw, I just discovered this tool yesterday and am already kicking myself for not finding it 10 projects ago
![]()
Thanks for the great tool, I will be buying the full version after a little test project with it.
If you run into more problems, let me know.
Joined: 29-Apr-2005
Funny, I ran across this problem again, except the fix you mentioned above doesnt seem to work.
This time however, Im using a typed list as the datasource to the grid. Based upon what you said above, I thought that setting the mappingname for the tablestyle to the class name of the typed list, in this case 'VideoPresentersTypedList'. It doesnt seem to be working. Is there a different approach with Typed Lists vs. Collection Classes?
Since Im on this topic, another problem Ive run into with typed lists and datagrids is this.. Typed lists are by definition read only, but when bound to a datagrid, the datagrid thinks it allows new records and therefore shows the new row with the astrisk. When you have a collection class and you want to remove this new row from showing on a grid, you just have to set the property on the collection class AllowNew = false;. Why would the typed list not behave like a collectionclass with it's addnew prop set to false by default. Either way, how could I make it behave like its read only in the grid?
Thanks, jim
Joined: 29-Apr-2005
Ok, the second question in my post above was a pretty dumb one, I forgot about the readonly property of the datagrid itself. So that one is solved.