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";