Custom collection was binded at design time, but does not populates datagrid at run time...

S

SammyBar

Hi,

I'm trying to bind a custom collection class to a data grid, following the
guidelines from the article
http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx.
The problem is the article is in VisualBasic. I already get the collection
to be recognized as a Data Source by the IDE. It populated the DataGrid
correctly from the fields on the items object of the collection, but I can't
get the DataGrid to show the collection content at run time. It is my first
ever data binded form so may be the error is not with the collection itself
but with the handling of the DataGrid and Form itself.
My collection (DPersonaLightCollection) is a type safe collection of
DPersonaLight objects. It inherits from CollectionBase, and implements
IComponent, IBindingList for design time binding support. It looks to be
work good. The code for the WindowsForm that shows the collection is the
following. The DataGrid is named dataGridLocator. At design time I added the
control fPersonaLightCollection. The dataGridLocator was set up at design
time with DataSource fPersonaLightCollection. I left DataMember in blank. On
the Form Load event I fill fPersonaLightCollection with 3 objects to show.
When the program runs, nothing is displayed, only the column headers that
were loaded at design time. What I'm doing wrong?
Thanks in advance
Sammy

using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using DBS.Interfaces.Basics;
using DBS.Interfaces.Persona;

namespace DBS.Client.Test
{
/// <summary>
/// Summary description for FormPersona.
/// </summary>
public class FormPersona : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl;
private System.Windows.Forms.TabPage tabLocator;
private System.Windows.Forms.TabPage tabGeneral;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.DataGrid dataGridLocator;
private System.Windows.Forms.TextBox textBoxDescription;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBoxSearchNombre;
private System.Windows.Forms.Button buttonSearch;
private DBS.Interfaces.Persona.DPersonaLightCollection
fPersonaLightCollection;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public FormPersona()
{
//
// 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()
{
this.tabControl = new System.Windows.Forms.TabControl();
this.tabLocator = new System.Windows.Forms.TabPage();
this.buttonSearch = new System.Windows.Forms.Button();
this.textBoxSearchNombre = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.dataGridLocator = new System.Windows.Forms.DataGrid();
this.tabGeneral = new System.Windows.Forms.TabPage();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.textBoxDescription = new System.Windows.Forms.TextBox();
this.fPersonaLightCollection = new
DBS.Interfaces.Persona.DPersonaLightCollection();
this.tabControl.SuspendLayout();
this.tabLocator.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridLocator)).BeginInit();
this.SuspendLayout();
//
// tabControl
//
this.tabControl.Anchor = (((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.tabControl.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabLocator,
this.tabGeneral,
this.tabPage3});
this.tabControl.Location = new System.Drawing.Point(8, 80);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new System.Drawing.Size(712, 400);
this.tabControl.TabIndex = 0;
//
// tabLocator
//
this.tabLocator.Controls.AddRange(new System.Windows.Forms.Control[] {
this.buttonSearch,
this.textBoxSearchNombre,
this.label1,
this.dataGridLocator});
this.tabLocator.Location = new System.Drawing.Point(4, 22);
this.tabLocator.Name = "tabLocator";
this.tabLocator.Size = new System.Drawing.Size(704, 374);
this.tabLocator.TabIndex = 0;
this.tabLocator.Text = "Localizador";
//
// buttonSearch
//
this.buttonSearch.Location = new System.Drawing.Point(216, 8);
this.buttonSearch.Name = "buttonSearch";
this.buttonSearch.Size = new System.Drawing.Size(88, 24);
this.buttonSearch.TabIndex = 3;
this.buttonSearch.Text = "Buscar";
this.buttonSearch.Click += new
System.EventHandler(this.buttonSearch_Click);
//
// textBoxSearchNombre
//
this.textBoxSearchNombre.Location = new System.Drawing.Point(56, 8);
this.textBoxSearchNombre.Name = "textBoxSearchNombre";
this.textBoxSearchNombre.Size = new System.Drawing.Size(152, 20);
this.textBoxSearchNombre.TabIndex = 2;
this.textBoxSearchNombre.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Nombre:";
//
// dataGridLocator
//
this.dataGridLocator.Anchor = (((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.dataGridLocator.DataMember = "";
this.dataGridLocator.DataSource = this.fPersonaLightCollection;
this.dataGridLocator.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGridLocator.Location = new System.Drawing.Point(8, 32);
this.dataGridLocator.Name = "dataGridLocator";
this.dataGridLocator.Size = new System.Drawing.Size(688, 336);
this.dataGridLocator.TabIndex = 0;
//
// tabGeneral
//
this.tabGeneral.Location = new System.Drawing.Point(4, 22);
this.tabGeneral.Name = "tabGeneral";
this.tabGeneral.Size = new System.Drawing.Size(704, 374);
this.tabGeneral.TabIndex = 1;
this.tabGeneral.Text = "Generales";
//
// tabPage3
//
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Size = new System.Drawing.Size(704, 374);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "tabPage3";
//
// textBoxDescription
//
this.textBoxDescription.Anchor = ((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.textBoxDescription.Enabled = false;
this.textBoxDescription.Location = new System.Drawing.Point(8, 8);
this.textBoxDescription.Multiline = true;
this.textBoxDescription.Name = "textBoxDescription";
this.textBoxDescription.Size = new System.Drawing.Size(712, 64);
this.textBoxDescription.TabIndex = 1;
this.textBoxDescription.Text = "";
//
// FormPersona
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(728, 486);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBoxDescription,
this.tabControl});
this.Name = "FormPersona";
this.Text = "FormPersona";
this.Load += new System.EventHandler(this.FormPersona_Load);
this.tabControl.ResumeLayout(false);
this.tabLocator.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridLocator)).EndInit();
this.ResumeLayout(false);

}
#endregion

private void buttonSearch_Click(object sender, System.EventArgs e)
{
UIControllerPersona ctrlPersona = new UIControllerPersona();
ctrlPersona.InitializeRemoting();
DDataCollectionContainer containerPersonas = ctrlPersona.SearchPersona();
this.fPersonaLightCollection =
(DPersonaLightCollection)containerPersonas.Collection;
this.dataGridLocator.Refresh();
}

private void FormPersona_Load(object sender, System.EventArgs e)
{
DPersonaLight persona = new DPersonaLight();
persona.ApellidoMaterno.Value = "KK1";
persona.ApellidoPaterno.Value = "KK2";
persona.DireccionPostal.Value = "KK3";
persona.Id.Value = 1;
persona.Key.Value = "KK4";
persona.Nombres.Value = "KK5";
persona.Telefonos.Value = "KK6";
this.fPersonaLightCollection.Add(persona);

persona = new DPersonaLight();
persona.ApellidoMaterno.Value = "PP1";
persona.ApellidoPaterno.Value = "PP2";
persona.DireccionPostal.Value = "PP3";
persona.Id.Value = 2;
persona.Key.Value = "PP4";
persona.Nombres.Value = "PP5";
persona.Telefonos.Value = "PP6";
this.fPersonaLightCollection.Add(persona);
}
}
}

The DPersonaLightCollection class is:

using System;
using System.Collections;
using System.ComponentModel;

namespace DBS.Interfaces.Persona
{
/// <summary>
/// Summary description for DPersonaLightCollection.
/// </summary>
[Serializable]
public class DPersonaLightCollection : CollectionBase, IComponent,
IBindingList
{
private ISite fSite;

public DPersonaLightCollection() : base()
{
fSite = null;
}

//--- IBindingList ---
public event ListChangedEventHandler ListChanged;

public bool AllowEdit { get { return false; } }
public bool AllowNew { get { return false; } }
public bool AllowRemove { get { return false; } }
public bool IsSorted { get { return false; } }
public ListSortDirection SortDirection { get { throw new
NotSupportedException(); } }
public PropertyDescriptor SortProperty {get { throw new
NotSupportedException(); }}
public bool SupportsChangeNotification {get { return false;} }
public bool SupportsSearching {get { return false;} }
public bool SupportsSorting {get { return false;} }

public void AddIndex(PropertyDescriptor property) { }
public object AddNew() { throw new NotSupportedException(); }
public void ApplySort(PropertyDescriptor property,ListSortDirection
direction) { throw new NotSupportedException(); }
public int Find(PropertyDescriptor property,object key) { throw new
NotSupportedException(); }
public void RemoveIndex(PropertyDescriptor property) {}
public void RemoveSort(){ throw new NotSupportedException(); }

//--- IComponent ---
public event EventHandler Disposed;

public ISite Site
{
get { return fSite; }
set { fSite = value; }
}

public void Dispose()
{
this.List.Clear();
if (this.fSite != null && this.fSite.Container != null)
fSite.Container.Remove(this);
Disposed(this, System.EventArgs.Empty);
}

//--- IList ---
public int Add(DPersonaLight aPersonaLight)
{
return this.List.Add(aPersonaLight);
}

public void Remove(DPersonaLight aPersonaLight)
{
this.List.Remove(aPersonaLight);
}

public bool Contains(DPersonaLight aPersonaLight)
{
return this.List.Contains(aPersonaLight);
}

public int IndexOf(DPersonaLight aPersonaLight)
{
return this.List.IndexOf(aPersonaLight);
}

public void Insert(int index, DPersonaLight aPersonaLight)
{
this.List.Insert(index, aPersonaLight);
}

public void CopyTo(Array array, int start)
{
List.CopyTo(array, start);
}

public DPersonaLight this[int index]
{
get { return (DPersonaLight)List[index]; }
set { Insert(index,value); }
}

protected override void OnValidate(object value)
{
base.OnValidate(value);
if (!(value is DPersonaLight))
{
throw new ArgumentException("Collection only supports DPersonaLight
objects.");
}
}
}
}
 
B

Bart Mermuys

Hi,

SammyBar said:
Hi,

I'm trying to bind a custom collection class to a data grid, following the
guidelines from the article
http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx.
The problem is the article is in VisualBasic. I already get the collection
to be recognized as a Data Source by the IDE. It populated the DataGrid
correctly from the fields on the items object of the collection, but I
can't get the DataGrid to show the collection content at run time. It is
my first ever data binded form so may be the error is not with the
collection itself but with the handling of the DataGrid and Form itself.
My collection (DPersonaLightCollection) is a type safe collection of
DPersonaLight objects. It inherits from CollectionBase, and implements
IComponent, IBindingList for design time binding support. It looks to be
work good. The code for the WindowsForm that shows the collection is the
following. The DataGrid is named dataGridLocator. At design time I added
the control fPersonaLightCollection. The dataGridLocator was set up at
design time with DataSource fPersonaLightCollection. I left DataMember in
blank. On the Form Load event I fill fPersonaLightCollection with 3
objects to show. When the program runs, nothing is displayed, only the
column headers that were loaded at design time. What I'm doing wrong?
Thanks in advance
Sammy

The problem is that you didn't implement change notification, so the
DataGrid doesn't know there are new items. You need to add/change some
things to the custom collection:

1. SupportsChangeNotification must return true:

public bool SupportsChangeNotification {get { return true;} }


2. You have to add methods so that the ListChanged event fires when the list
is changed:

protected virtual void OnListChanged( ListChangedEventArgs e )
{
if ( ListChanged!=null )
ListChanged( this, e );
}

protected override void OnInsertComplete(int index, object value)
{
OnListChanged( new ListChangedEventArgs(
ListChangedType.ItemAdded, index ) );
}

protected override void OnRemoveComplete(int index, object value)
{
OnListChanged( new ListChangedEventArgs(
ListChangedType.ItemDeleted, index ));
}

protected override void OnSetComplete( int index, object value )
{
OnListChanged( new ListChangedEventArgs(
ListChangedType.ItemChanged, index ));
}


3. The indexer is wrong and should be:
public DPersonaLight this[int index]
{
get { return (DPersonaLight)List[index]; }
set { List[index] = value; }
}


HTH,
Greetings

using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using DBS.Interfaces.Basics;
using DBS.Interfaces.Persona;

namespace DBS.Client.Test
{
/// <summary>
/// Summary description for FormPersona.
/// </summary>
public class FormPersona : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl;
private System.Windows.Forms.TabPage tabLocator;
private System.Windows.Forms.TabPage tabGeneral;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.DataGrid dataGridLocator;
private System.Windows.Forms.TextBox textBoxDescription;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBoxSearchNombre;
private System.Windows.Forms.Button buttonSearch;
private DBS.Interfaces.Persona.DPersonaLightCollection
fPersonaLightCollection;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public FormPersona()
{
//
// 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()
{
this.tabControl = new System.Windows.Forms.TabControl();
this.tabLocator = new System.Windows.Forms.TabPage();
this.buttonSearch = new System.Windows.Forms.Button();
this.textBoxSearchNombre = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.dataGridLocator = new System.Windows.Forms.DataGrid();
this.tabGeneral = new System.Windows.Forms.TabPage();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.textBoxDescription = new System.Windows.Forms.TextBox();
this.fPersonaLightCollection = new
DBS.Interfaces.Persona.DPersonaLightCollection();
this.tabControl.SuspendLayout();
this.tabLocator.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.dataGridLocator)).BeginInit();
this.SuspendLayout();
//
// tabControl
//
this.tabControl.Anchor = (((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.tabControl.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabLocator,
this.tabGeneral,
this.tabPage3});
this.tabControl.Location = new System.Drawing.Point(8, 80);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new System.Drawing.Size(712, 400);
this.tabControl.TabIndex = 0;
//
// tabLocator
//
this.tabLocator.Controls.AddRange(new System.Windows.Forms.Control[] {
this.buttonSearch,
this.textBoxSearchNombre,
this.label1,
this.dataGridLocator});
this.tabLocator.Location = new System.Drawing.Point(4, 22);
this.tabLocator.Name = "tabLocator";
this.tabLocator.Size = new System.Drawing.Size(704, 374);
this.tabLocator.TabIndex = 0;
this.tabLocator.Text = "Localizador";
//
// buttonSearch
//
this.buttonSearch.Location = new System.Drawing.Point(216, 8);
this.buttonSearch.Name = "buttonSearch";
this.buttonSearch.Size = new System.Drawing.Size(88, 24);
this.buttonSearch.TabIndex = 3;
this.buttonSearch.Text = "Buscar";
this.buttonSearch.Click += new
System.EventHandler(this.buttonSearch_Click);
//
// textBoxSearchNombre
//
this.textBoxSearchNombre.Location = new System.Drawing.Point(56, 8);
this.textBoxSearchNombre.Name = "textBoxSearchNombre";
this.textBoxSearchNombre.Size = new System.Drawing.Size(152, 20);
this.textBoxSearchNombre.TabIndex = 2;
this.textBoxSearchNombre.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Nombre:";
//
// dataGridLocator
//
this.dataGridLocator.Anchor = (((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.dataGridLocator.DataMember = "";
this.dataGridLocator.DataSource = this.fPersonaLightCollection;
this.dataGridLocator.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGridLocator.Location = new System.Drawing.Point(8, 32);
this.dataGridLocator.Name = "dataGridLocator";
this.dataGridLocator.Size = new System.Drawing.Size(688, 336);
this.dataGridLocator.TabIndex = 0;
//
// tabGeneral
//
this.tabGeneral.Location = new System.Drawing.Point(4, 22);
this.tabGeneral.Name = "tabGeneral";
this.tabGeneral.Size = new System.Drawing.Size(704, 374);
this.tabGeneral.TabIndex = 1;
this.tabGeneral.Text = "Generales";
//
// tabPage3
//
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Size = new System.Drawing.Size(704, 374);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "tabPage3";
//
// textBoxDescription
//
this.textBoxDescription.Anchor = ((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.textBoxDescription.Enabled = false;
this.textBoxDescription.Location = new System.Drawing.Point(8, 8);
this.textBoxDescription.Multiline = true;
this.textBoxDescription.Name = "textBoxDescription";
this.textBoxDescription.Size = new System.Drawing.Size(712, 64);
this.textBoxDescription.TabIndex = 1;
this.textBoxDescription.Text = "";
//
// FormPersona
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(728, 486);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBoxDescription,
this.tabControl});
this.Name = "FormPersona";
this.Text = "FormPersona";
this.Load += new System.EventHandler(this.FormPersona_Load);
this.tabControl.ResumeLayout(false);
this.tabLocator.ResumeLayout(false);

((System.ComponentModel.ISupportInitialize)(this.dataGridLocator)).EndInit();
this.ResumeLayout(false);

}
#endregion

private void buttonSearch_Click(object sender, System.EventArgs e)
{
UIControllerPersona ctrlPersona = new UIControllerPersona();
ctrlPersona.InitializeRemoting();
DDataCollectionContainer containerPersonas =
ctrlPersona.SearchPersona();
this.fPersonaLightCollection =
(DPersonaLightCollection)containerPersonas.Collection;
this.dataGridLocator.Refresh();
}

private void FormPersona_Load(object sender, System.EventArgs e)
{
DPersonaLight persona = new DPersonaLight();
persona.ApellidoMaterno.Value = "KK1";
persona.ApellidoPaterno.Value = "KK2";
persona.DireccionPostal.Value = "KK3";
persona.Id.Value = 1;
persona.Key.Value = "KK4";
persona.Nombres.Value = "KK5";
persona.Telefonos.Value = "KK6";
this.fPersonaLightCollection.Add(persona);

persona = new DPersonaLight();
persona.ApellidoMaterno.Value = "PP1";
persona.ApellidoPaterno.Value = "PP2";
persona.DireccionPostal.Value = "PP3";
persona.Id.Value = 2;
persona.Key.Value = "PP4";
persona.Nombres.Value = "PP5";
persona.Telefonos.Value = "PP6";
this.fPersonaLightCollection.Add(persona);
}
}
}

The DPersonaLightCollection class is:

using System;
using System.Collections;
using System.ComponentModel;

namespace DBS.Interfaces.Persona
{
/// <summary>
/// Summary description for DPersonaLightCollection.
/// </summary>
[Serializable]
public class DPersonaLightCollection : CollectionBase, IComponent,
IBindingList
{
private ISite fSite;

public DPersonaLightCollection() : base()
{
fSite = null;
}

//--- IBindingList ---
public event ListChangedEventHandler ListChanged;

public bool AllowEdit { get { return false; } }
public bool AllowNew { get { return false; } }
public bool AllowRemove { get { return false; } }
public bool IsSorted { get { return false; } }
public ListSortDirection SortDirection { get { throw new
NotSupportedException(); } }
public PropertyDescriptor SortProperty {get { throw new
NotSupportedException(); }}
public bool SupportsChangeNotification {get { return false;} }
public bool SupportsSearching {get { return false;} }
public bool SupportsSorting {get { return false;} }

public void AddIndex(PropertyDescriptor property) { }
public object AddNew() { throw new NotSupportedException(); }
public void ApplySort(PropertyDescriptor property,ListSortDirection
direction) { throw new NotSupportedException(); }
public int Find(PropertyDescriptor property,object key) { throw new
NotSupportedException(); }
public void RemoveIndex(PropertyDescriptor property) {}
public void RemoveSort(){ throw new NotSupportedException(); }

//--- IComponent ---
public event EventHandler Disposed;

public ISite Site
{
get { return fSite; }
set { fSite = value; }
}

public void Dispose()
{
this.List.Clear();
if (this.fSite != null && this.fSite.Container != null)
fSite.Container.Remove(this);
Disposed(this, System.EventArgs.Empty);
}

//--- IList ---
public int Add(DPersonaLight aPersonaLight)
{
return this.List.Add(aPersonaLight);
}

public void Remove(DPersonaLight aPersonaLight)
{
this.List.Remove(aPersonaLight);
}

public bool Contains(DPersonaLight aPersonaLight)
{
return this.List.Contains(aPersonaLight);
}

public int IndexOf(DPersonaLight aPersonaLight)
{
return this.List.IndexOf(aPersonaLight);
}

public void Insert(int index, DPersonaLight aPersonaLight)
{
this.List.Insert(index, aPersonaLight);
}

public void CopyTo(Array array, int start)
{
List.CopyTo(array, start);
}

public DPersonaLight this[int index]
{
get { return (DPersonaLight)List[index]; }
set { Insert(index,value); }
}

protected override void OnValidate(object value)
{
base.OnValidate(value);
if (!(value is DPersonaLight))
{
throw new ArgumentException("Collection only supports DPersonaLight
objects.");
}
}
}
}
 
S

SammyBar

The problem is that you didn't implement change notification, so the
DataGrid doesn't know there are new items. You need to add/change some
things to the custom collection:

Ok, thanks, I'll try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top