Custom control with Collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I create a custom control with a collection property. My question is : Can I
override the method add of Collection ?
 
Maybe could be a good idea if you creates a class that derives from
collectionbase, this way you can add, get, delete, modify members of your
collection...

Hope this helps.
Josema.
 
I do this. I create a class derives from collectionbase and implemented the
method add. But when add the items on Collection Editor Dialog Box, my method
add not is excecuted.

Sorry for my english. It's horrible.
 
Hi, Rogerio

Could you post a piece of code? this way, we can see why you add method
its not executing correctly...

Regards.
Josema.
 
using System;
using System.Collections;
using System.Windows.Forms;

namespace Nox.Componente
{
/// <summary>
/// Summary description for WizardPage.
/// </summary>
public class WizardPage
{
// Variáveis locais
private string _Name;
private string _Title;

// Propriedades
public string Name
{
get {return _Name;}
set {_Name = value;}
}

public string Title
{
get {return _Title;}
set {_Title = value;}
}

// Métodos
public WizardPage()
{

}
}

public class WizardPages: CollectionBase
{

private WizardControl Owner;

public WizardPages()
{
}

public WizardPages(WizardControl Objeto)
{
Owner = Objeto;
}

public WizardPage this[int index]
{
get
{
return (WizardPage) List[index];
}
}

public void Add(WizardPage Page)
{
if (Page != null)
{
List.Add(Page);

TabPage Pagina = new TabPage(Page.Title);
Owner.TabControl.Controls.Add(Pagina);
Pagina.Dispose();
}
}
}
}
 
Hi Rogerio.
I see your code, but i dont know wxactly what is you want to do...

I dont know if this can help to you but generally i make something like
this:

I create the custom control

public class WizardControl:WebControl
{
protected override OnInit()
{
//Make an instance of the Collection base
//Call to a method to fill de collection
//Populate this control with the collection
}

}

public class WizardPages:CollectionBase
{
public void FillCollection()
{
//Instance to the class that takes the data
//Subscribing to the event created by you in the class where
you take the data (from database, or from xml file, etc...


}
public WizardPage Get_(int index)
{
return List[index]
}
public void Add_(WizardPage tempwizardpage)
{
List.Add(tempwizardpage);
}
public void Delete_(WizardPage tempwizardpage)
{
List.Delete(tempwizardpage);
}
private void WizardPageFound(object sender, EventArgs e)
{
WizardPage tempwizardpage=(WizardPage) sender;
this.Add_(tempwizardpage);
}
}
//For instance this could be a class to recover data...
public class Database()
{
//define the event (the event wich i will subscribe in the Wizards
Collection class.
public event EventHandler WizardFound;
//define the method that will fire the event
public virtual void OnWizardFound(object sender, EventArgs e)
{
if(WizardFount!=null)
{
WizardFound(sender,e);
}
}
//the method that will be take info from (for example) database
public void GetWizardPages()
{
//Connect to database
//Call stored procedure for example
//for each WizardPage got, call OnWizardFound()
//disconnect from database
}
}

I dont know if this case its similar than yours, but maybe gives to you
a light in the dark.

Hope this helps...

Regards.
Josema.
 
Back
Top