473,835 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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/is...g/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 (DPersonaLightC ollection) 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 fPersonaLightCo llection. The dataGridLocator was set up at design
time with DataSource fPersonaLightCo llection. I left DataMember in blank. On
the Form Load event I fill fPersonaLightCo llection 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.Collecti ons;
using System.Componen tModel;
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.TabContro l 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 textBoxDescript ion;
private System.Windows. Forms.Label label1;
private System.Windows. Forms.TextBox textBoxSearchNo mbre;
private System.Windows. Forms.Button buttonSearch;
private DBS.Interfaces. Persona.DPerson aLightCollectio n
fPersonaLightCo llection;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public FormPersona()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
this.tabControl = new System.Windows. Forms.TabContro l();
this.tabLocator = new System.Windows. Forms.TabPage() ;
this.buttonSear ch = new System.Windows. Forms.Button();
this.textBoxSea rchNombre = new System.Windows. Forms.TextBox() ;
this.label1 = new System.Windows. Forms.Label();
this.dataGridLo cator = new System.Windows. Forms.DataGrid( );
this.tabGeneral = new System.Windows. Forms.TabPage() ;
this.tabPage3 = new System.Windows. Forms.TabPage() ;
this.textBoxDes cription = new System.Windows. Forms.TextBox() ;
this.fPersonaLi ghtCollection = new
DBS.Interfaces. Persona.DPerson aLightCollectio n();
this.tabControl .SuspendLayout( );
this.tabLocator .SuspendLayout( );
((System.Compon entModel.ISuppo rtInitialize)(t his.dataGridLoc ator)).BeginIni t();
this.SuspendLay out();
//
// tabControl
//
this.tabControl .Anchor = (((System.Windo ws.Forms.Anchor Styles.Top |
System.Windows. Forms.AnchorSty les.Bottom)
| System.Windows. Forms.AnchorSty les.Left)
| System.Windows. Forms.AnchorSty les.Right);
this.tabControl .Controls.AddRa nge(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.AddRa nge(new System.Windows. Forms.Control[] {
this.buttonSear ch,
this.textBoxSea rchNombre,
this.label1,
this.dataGridLo cator});
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 = "Localizado r";
//
// buttonSearch
//
this.buttonSear ch.Location = new System.Drawing. Point(216, 8);
this.buttonSear ch.Name = "buttonSear ch";
this.buttonSear ch.Size = new System.Drawing. Size(88, 24);
this.buttonSear ch.TabIndex = 3;
this.buttonSear ch.Text = "Buscar";
this.buttonSear ch.Click += new
System.EventHan dler(this.butto nSearch_Click);
//
// textBoxSearchNo mbre
//
this.textBoxSea rchNombre.Locat ion = new System.Drawing. Point(56, 8);
this.textBoxSea rchNombre.Name = "textBoxSearchN ombre";
this.textBoxSea rchNombre.Size = new System.Drawing. Size(152, 20);
this.textBoxSea rchNombre.TabIn dex = 2;
this.textBoxSea rchNombre.Text = "";
//
// label1
//
this.label1.Loc ation = new System.Drawing. Point(8, 8);
this.label1.Nam e = "label1";
this.label1.Siz e = new System.Drawing. Size(48, 16);
this.label1.Tab Index = 1;
this.label1.Tex t = "Nombre:";
//
// dataGridLocator
//
this.dataGridLo cator.Anchor = (((System.Windo ws.Forms.Anchor Styles.Top |
System.Windows. Forms.AnchorSty les.Bottom)
| System.Windows. Forms.AnchorSty les.Left)
| System.Windows. Forms.AnchorSty les.Right);
this.dataGridLo cator.DataMembe r = "";
this.dataGridLo cator.DataSourc e = this.fPersonaLi ghtCollection;
this.dataGridLo cator.HeaderFor eColor =
System.Drawing. SystemColors.Co ntrolText;
this.dataGridLo cator.Location = new System.Drawing. Point(8, 32);
this.dataGridLo cator.Name = "dataGridLocato r";
this.dataGridLo cator.Size = new System.Drawing. Size(688, 336);
this.dataGridLo cator.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.L ocation = new System.Drawing. Point(4, 22);
this.tabPage3.N ame = "tabPage3";
this.tabPage3.S ize = new System.Drawing. Size(704, 374);
this.tabPage3.T abIndex = 2;
this.tabPage3.T ext = "tabPage3";
//
// textBoxDescript ion
//
this.textBoxDes cription.Anchor = ((System.Window s.Forms.AnchorS tyles.Top
| System.Windows. Forms.AnchorSty les.Left)
| System.Windows. Forms.AnchorSty les.Right);
this.textBoxDes cription.Enable d = false;
this.textBoxDes cription.Locati on = new System.Drawing. Point(8, 8);
this.textBoxDes cription.Multil ine = true;
this.textBoxDes cription.Name = "textBoxDescrip tion";
this.textBoxDes cription.Size = new System.Drawing. Size(712, 64);
this.textBoxDes cription.TabInd ex = 1;
this.textBoxDes cription.Text = "";
//
// FormPersona
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(728, 486);
this.Controls.A ddRange(new System.Windows. Forms.Control[] {
this.textBoxDes cription,
this.tabControl });
this.Name = "FormPerson a";
this.Text = "FormPerson a";
this.Load += new System.EventHan dler(this.FormP ersona_Load);
this.tabControl .ResumeLayout(f alse);
this.tabLocator .ResumeLayout(f alse);
((System.Compon entModel.ISuppo rtInitialize)(t his.dataGridLoc ator)).EndInit( );
this.ResumeLayo ut(false);

}
#endregion

private void buttonSearch_Cl ick(object sender, System.EventArg s e)
{
UIControllerPer sona ctrlPersona = new UIControllerPer sona();
ctrlPersona.Ini tializeRemoting ();
DDataCollection Container containerPerson as = ctrlPersona.Sea rchPersona();
this.fPersonaLi ghtCollection =
(DPersonaLightC ollection)conta inerPersonas.Co llection;
this.dataGridLo cator.Refresh() ;
}

private void FormPersona_Loa d(object sender, System.EventArg s e)
{
DPersonaLight persona = new DPersonaLight() ;
persona.Apellid oMaterno.Value = "KK1";
persona.Apellid oPaterno.Value = "KK2";
persona.Direcci onPostal.Value = "KK3";
persona.Id.Valu e = 1;
persona.Key.Val ue = "KK4";
persona.Nombres .Value = "KK5";
persona.Telefon os.Value = "KK6";
this.fPersonaLi ghtCollection.A dd(persona);

persona = new DPersonaLight() ;
persona.Apellid oMaterno.Value = "PP1";
persona.Apellid oPaterno.Value = "PP2";
persona.Direcci onPostal.Value = "PP3";
persona.Id.Valu e = 2;
persona.Key.Val ue = "PP4";
persona.Nombres .Value = "PP5";
persona.Telefon os.Value = "PP6";
this.fPersonaLi ghtCollection.A dd(persona);
}
}
}

The DPersonaLightCo llection class is:

using System;
using System.Collecti ons;
using System.Componen tModel;

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

public DPersonaLightCo llection() : base()
{
fSite = null;
}

//--- IBindingList ---
public event ListChangedEven tHandler 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 ListSortDirecti on SortDirection { get { throw new
NotSupportedExc eption(); } }
public PropertyDescrip tor SortProperty {get { throw new
NotSupportedExc eption(); }}
public bool SupportsChangeN otification {get { return false;} }
public bool SupportsSearchi ng {get { return false;} }
public bool SupportsSorting {get { return false;} }

public void AddIndex(Proper tyDescriptor property) { }
public object AddNew() { throw new NotSupportedExc eption(); }
public void ApplySort(Prope rtyDescriptor property,ListSo rtDirection
direction) { throw new NotSupportedExc eption(); }
public int Find(PropertyDe scriptor property,object key) { throw new
NotSupportedExc eption(); }
public void RemoveIndex(Pro pertyDescriptor property) {}
public void RemoveSort(){ throw new NotSupportedExc eption(); }

//--- 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.Cont ainer != null)
fSite.Container .Remove(this);
Disposed(this, System.EventArg s.Empty);
}

//--- IList ---
public int Add(DPersonaLig ht aPersonaLight)
{
return this.List.Add(a PersonaLight);
}

public void Remove(DPersona Light aPersonaLight)
{
this.List.Remov e(aPersonaLight );
}

public bool Contains(DPerso naLight aPersonaLight)
{
return this.List.Conta ins(aPersonaLig ht);
}

public int IndexOf(DPerson aLight aPersonaLight)
{
return this.List.Index Of(aPersonaLigh t);
}

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

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

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

protected override void OnValidate(obje ct value)
{
base.OnValidate (value);
if (!(value is DPersonaLight))
{
throw new ArgumentExcepti on("Collection only supports DPersonaLight
objects.");
}
}
}
}
Sep 21 '05 #1
2 2774
Hi,

"SammyBar" <sa******@gmail .com> wrote in message
news:ON******** ******@TK2MSFTN GP12.phx.gbl...
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/is...g/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 (DPersonaLightC ollection) 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 fPersonaLightCo llection. The dataGridLocator was set up at
design time with DataSource fPersonaLightCo llection. I left DataMember in
blank. On the Form Load event I fill fPersonaLightCo llection 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. SupportsChangeN otification must return true:

public bool SupportsChangeN otification {get { return true;} }
2. You have to add methods so that the ListChanged event fires when the list
is changed:

protected virtual void OnListChanged( ListChangedEven tArgs e )
{
if ( ListChanged!=nu ll )
ListChanged( this, e );
}

protected override void OnInsertComplet e(int index, object value)
{
OnListChanged( new ListChangedEven tArgs(
ListChangedType .ItemAdded, index ) );
}

protected override void OnRemoveComplet e(int index, object value)
{
OnListChanged( new ListChangedEven tArgs(
ListChangedType .ItemDeleted, index ));
}

protected override void OnSetComplete( int index, object value )
{
OnListChanged( new ListChangedEven tArgs(
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.Collecti ons;
using System.Componen tModel;
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.TabContro l 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 textBoxDescript ion;
private System.Windows. Forms.Label label1;
private System.Windows. Forms.TextBox textBoxSearchNo mbre;
private System.Windows. Forms.Button buttonSearch;
private DBS.Interfaces. Persona.DPerson aLightCollectio n
fPersonaLightCo llection;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public FormPersona()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
this.tabControl = new System.Windows. Forms.TabContro l();
this.tabLocator = new System.Windows. Forms.TabPage() ;
this.buttonSear ch = new System.Windows. Forms.Button();
this.textBoxSea rchNombre = new System.Windows. Forms.TextBox() ;
this.label1 = new System.Windows. Forms.Label();
this.dataGridLo cator = new System.Windows. Forms.DataGrid( );
this.tabGeneral = new System.Windows. Forms.TabPage() ;
this.tabPage3 = new System.Windows. Forms.TabPage() ;
this.textBoxDes cription = new System.Windows. Forms.TextBox() ;
this.fPersonaLi ghtCollection = new
DBS.Interfaces. Persona.DPerson aLightCollectio n();
this.tabControl .SuspendLayout( );
this.tabLocator .SuspendLayout( );

((System.Compon entModel.ISuppo rtInitialize)(t his.dataGridLoc ator)).BeginIni t();
this.SuspendLay out();
//
// tabControl
//
this.tabControl .Anchor = (((System.Windo ws.Forms.Anchor Styles.Top |
System.Windows. Forms.AnchorSty les.Bottom)
| System.Windows. Forms.AnchorSty les.Left)
| System.Windows. Forms.AnchorSty les.Right);
this.tabControl .Controls.AddRa nge(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.AddRa nge(new System.Windows. Forms.Control[] {
this.buttonSear ch,
this.textBoxSea rchNombre,
this.label1,
this.dataGridLo cator});
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 = "Localizado r";
//
// buttonSearch
//
this.buttonSear ch.Location = new System.Drawing. Point(216, 8);
this.buttonSear ch.Name = "buttonSear ch";
this.buttonSear ch.Size = new System.Drawing. Size(88, 24);
this.buttonSear ch.TabIndex = 3;
this.buttonSear ch.Text = "Buscar";
this.buttonSear ch.Click += new
System.EventHan dler(this.butto nSearch_Click);
//
// textBoxSearchNo mbre
//
this.textBoxSea rchNombre.Locat ion = new System.Drawing. Point(56, 8);
this.textBoxSea rchNombre.Name = "textBoxSearchN ombre";
this.textBoxSea rchNombre.Size = new System.Drawing. Size(152, 20);
this.textBoxSea rchNombre.TabIn dex = 2;
this.textBoxSea rchNombre.Text = "";
//
// label1
//
this.label1.Loc ation = new System.Drawing. Point(8, 8);
this.label1.Nam e = "label1";
this.label1.Siz e = new System.Drawing. Size(48, 16);
this.label1.Tab Index = 1;
this.label1.Tex t = "Nombre:";
//
// dataGridLocator
//
this.dataGridLo cator.Anchor = (((System.Windo ws.Forms.Anchor Styles.Top |
System.Windows. Forms.AnchorSty les.Bottom)
| System.Windows. Forms.AnchorSty les.Left)
| System.Windows. Forms.AnchorSty les.Right);
this.dataGridLo cator.DataMembe r = "";
this.dataGridLo cator.DataSourc e = this.fPersonaLi ghtCollection;
this.dataGridLo cator.HeaderFor eColor =
System.Drawing. SystemColors.Co ntrolText;
this.dataGridLo cator.Location = new System.Drawing. Point(8, 32);
this.dataGridLo cator.Name = "dataGridLocato r";
this.dataGridLo cator.Size = new System.Drawing. Size(688, 336);
this.dataGridLo cator.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.L ocation = new System.Drawing. Point(4, 22);
this.tabPage3.N ame = "tabPage3";
this.tabPage3.S ize = new System.Drawing. Size(704, 374);
this.tabPage3.T abIndex = 2;
this.tabPage3.T ext = "tabPage3";
//
// textBoxDescript ion
//
this.textBoxDes cription.Anchor = ((System.Window s.Forms.AnchorS tyles.Top
| System.Windows. Forms.AnchorSty les.Left)
| System.Windows. Forms.AnchorSty les.Right);
this.textBoxDes cription.Enable d = false;
this.textBoxDes cription.Locati on = new System.Drawing. Point(8, 8);
this.textBoxDes cription.Multil ine = true;
this.textBoxDes cription.Name = "textBoxDescrip tion";
this.textBoxDes cription.Size = new System.Drawing. Size(712, 64);
this.textBoxDes cription.TabInd ex = 1;
this.textBoxDes cription.Text = "";
//
// FormPersona
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(728, 486);
this.Controls.A ddRange(new System.Windows. Forms.Control[] {
this.textBoxDes cription,
this.tabControl });
this.Name = "FormPerson a";
this.Text = "FormPerson a";
this.Load += new System.EventHan dler(this.FormP ersona_Load);
this.tabControl .ResumeLayout(f alse);
this.tabLocator .ResumeLayout(f alse);

((System.Compon entModel.ISuppo rtInitialize)(t his.dataGridLoc ator)).EndInit( );
this.ResumeLayo ut(false);

}
#endregion

private void buttonSearch_Cl ick(object sender, System.EventArg s e)
{
UIControllerPer sona ctrlPersona = new UIControllerPer sona();
ctrlPersona.Ini tializeRemoting ();
DDataCollection Container containerPerson as =
ctrlPersona.Sea rchPersona();
this.fPersonaLi ghtCollection =
(DPersonaLightC ollection)conta inerPersonas.Co llection;
this.dataGridLo cator.Refresh() ;
}

private void FormPersona_Loa d(object sender, System.EventArg s e)
{
DPersonaLight persona = new DPersonaLight() ;
persona.Apellid oMaterno.Value = "KK1";
persona.Apellid oPaterno.Value = "KK2";
persona.Direcci onPostal.Value = "KK3";
persona.Id.Valu e = 1;
persona.Key.Val ue = "KK4";
persona.Nombres .Value = "KK5";
persona.Telefon os.Value = "KK6";
this.fPersonaLi ghtCollection.A dd(persona);

persona = new DPersonaLight() ;
persona.Apellid oMaterno.Value = "PP1";
persona.Apellid oPaterno.Value = "PP2";
persona.Direcci onPostal.Value = "PP3";
persona.Id.Valu e = 2;
persona.Key.Val ue = "PP4";
persona.Nombres .Value = "PP5";
persona.Telefon os.Value = "PP6";
this.fPersonaLi ghtCollection.A dd(persona);
}
}
}

The DPersonaLightCo llection class is:

using System;
using System.Collecti ons;
using System.Componen tModel;

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

public DPersonaLightCo llection() : base()
{
fSite = null;
}

//--- IBindingList ---
public event ListChangedEven tHandler 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 ListSortDirecti on SortDirection { get { throw new
NotSupportedExc eption(); } }
public PropertyDescrip tor SortProperty {get { throw new
NotSupportedExc eption(); }}
public bool SupportsChangeN otification {get { return false;} }
public bool SupportsSearchi ng {get { return false;} }
public bool SupportsSorting {get { return false;} }

public void AddIndex(Proper tyDescriptor property) { }
public object AddNew() { throw new NotSupportedExc eption(); }
public void ApplySort(Prope rtyDescriptor property,ListSo rtDirection
direction) { throw new NotSupportedExc eption(); }
public int Find(PropertyDe scriptor property,object key) { throw new
NotSupportedExc eption(); }
public void RemoveIndex(Pro pertyDescriptor property) {}
public void RemoveSort(){ throw new NotSupportedExc eption(); }

//--- 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.Cont ainer != null)
fSite.Container .Remove(this);
Disposed(this, System.EventArg s.Empty);
}

//--- IList ---
public int Add(DPersonaLig ht aPersonaLight)
{
return this.List.Add(a PersonaLight);
}

public void Remove(DPersona Light aPersonaLight)
{
this.List.Remov e(aPersonaLight );
}

public bool Contains(DPerso naLight aPersonaLight)
{
return this.List.Conta ins(aPersonaLig ht);
}

public int IndexOf(DPerson aLight aPersonaLight)
{
return this.List.Index Of(aPersonaLigh t);
}

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

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

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

protected override void OnValidate(obje ct value)
{
base.OnValidate (value);
if (!(value is DPersonaLight))
{
throw new ArgumentExcepti on("Collection only supports DPersonaLight
objects.");
}
}
}
}

Sep 21 '05 #2
> 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
Sep 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4836
by: craig | last post by:
Assume that you would like to create a custom collection class that is: 1. Strongly-typed (only holds Customer objects) 2. Read-only (user cannot add Customer objects) 3. Able to be bound to a winforms datagrid (must implement the IList interface). What would be a good way to create this class? 1. The CollectionBase abstract base class can be used, but it is not
6
1481
by: Ben | last post by:
Hi I've got a problem with a custon control that inherits form the UserControl class and that used the overlib javascript library. The control works well in a standard form but when I used it in a datagrid, the properties that were binded from the database doesn't keep their value through the page_load of the custom control. By using breakpoints on the properties methods of the control, I saw that they were all correctly binded and that the...
2
2211
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple properties, ProdID, Description, Quantity and UPC. 3 strings and a long. The LineItemsCollection class inherits from System.Collections.Specialized.NameObjectCollectionBase. It also implements both IEnumerable and IList.
7
3023
by: Shimon Sim | last post by:
I have a custom composite control I have following property
6
4369
by: Bob The Builder | last post by:
I have a custom-built datagrid for windows forms. I overrode the scrollbars in it because I wanted to draw my own (basically, they're skinned). As a result, I handle all scroll events and calls. I also have a row-selector column as the first column, and that needs to stay visible. Think Excel. However, if a user clicks a cell that is all the way to the right and goes off the grid a bit, then the entire grid shifts, including my...
2
2453
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just fine. However, when attempting to assing default values as designtime in the propertygrid, nothing is working on the class object. I know that I am doing it wrong, any ideas what it is? Thanks in advance
4
2543
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView Inherits System.Windows.Forms.UserControl Private _Collection As GridTableStylesCollection
2
346
by: SammyBar | last post by:
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...
9
4698
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate> /asp:Repeater> The DataSource for this Repeater is a CollectionBase of objects and is
0
9803
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10523
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7766
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3088
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.