Similar Threads:
1.Collection as sub-set of collection
This is about VB6, hope this is the right forum!
Say I have two collections: Cars and Manufacturers e.g.,
Cars = Focus, Escort, Puma, Cougar, 626, 323, Clio, Espace, 106, 206,
307
Manufacturers = Ford, Mazda, Renault, Peugeot
I have a couple of questions about inter-referencing between them:
1) Can each 'Car' reference the appropriate 'Manufacturer' object, such
that Cars("Focus").Manufacturer returns (a reference to) the same
object as Manufacturers("Ford")?
2) Can each 'Manufacturer' contain a 'MyCars' collection which is
essentially a subset of the 'Cars' collection, BUT REFERENCES THE SAME
OBJECTS. That is, say, if I do
Manufacturers("Ford") .MyCars("Focus").Age = 6
then
n = Cars("Focus").Age
n = 6
If this can be done, how?
If it can only be simulated, what is the best method?
Thanks very much,
Dan
2.Nester Collection, Collection within collection
Hi,
Is it possible to create a collection within another collection.
Here is the abstract of my object:
* Class 1 (consists of)
- Attr 1a
- Attr 1b
- Col 1 (collection of class 2)
* Class 2 (consists of)
- Attr 2a
- Attr 2b
- Col 2 (collection of class 3)
The db relation is Many to Many and I normalised to M-1-M, and I want to
impletement the same in the collection.
My second question:
I am using the creating collection method suggested in the MSDN disc e.g.:
in Class 2
Attr 2a (property Get/Let)
Attr 2b (property Get/Let)
Collection 2 (read from db and get all relevants entries and use Add
method attach
to the collection)
the collection 2's items are "populated" in this same module. That leads to
my question:
It is like a cascade method and each class "populates" its own collection
items ?
OR
the highest level class does ALL the "populating" the collection items and
sub-collection items?
I hope I have made myself clear. Thanks very much
Chwan Keng
3.Inheriting VB6 dll classes/collections into dotnet classes/collections
Hello
Currently what I am doing is inheriting vb6 classes into dotnet classes like
Public Class CEmploye
Inherits VB6DLLFile.clsEmploye
End Clas
This seems to work fine. My problem is inheriting a collection from the VB6 dll file. For example if I have a collection of Employees. Would it look like this
Public Class CEmployeeCollectio
Inherits VB6DLLFile.colEmployee
End Clas
How would I access the collection in a For Each loop? Currently I have something that looks like this
For Each CEmployee In CEmployeeCollection 'I am skipping all the Dim something As New Class stuff
debug.writeline(CEmployee.Name
Nex
I am getting a "Specified cast is not valid" error message with the above lines
I do not understand why. I am looking for anyone that can explain why that is happening
Thanks
Charle
4.Collection problems (create Collection object, add data to collection, bind collection to datagrid)
I try to make my own ArticleAttribute object and ArticleAttributeCollection,
and add data to this Collection. It almost works, but the problem is that
each time I add an ArticleAttribute to my Collection, it seems like it
overwrites the other ArticleAttributes. When bind the
ArticleAttributeCollection to a datagrid, all articleattributes are the
same.
This is what my datagrid dispays:
ID Content
2 Hello 2
2 Hello 2
2 Hello 2
It should be like this:
ID Content
0 Hello 0
1 Hello 1
2 Hello 2
-----------------------------------------------
Here is my ArticleAttributeCollection.cs
-----------------------------------------------
namespace Test
{
[Serializable()]
public class ArticleAttributeCollection : CollectionBase, IEnumerable
{
public void Insert(int index, ArticleAttribute ArticleAttribute)
{
base.List.Insert(index, ArticleAttribute);
}
public void Add(ArticleAttribute ArticleAttribute)
{
base.List.Add(ArticleAttribute);
}
public void Remove(ArticleAttribute ArticleAttribute)
{
base.List.Remove(ArticleAttribute);
}
public ArticleAttribute this[int index]
{
get
{
return (ArticleAttribute)(base.List[index]);
}
set
{
base.List[index] = value;
}
}
}
}
-----------------------------------------------
Here is my ArticleAttribute.cs
-----------------------------------------------
namespace Test
{
public class ArticleAttribute
{
public ArticleAttribute()
{
}
public ArticleAttribute(int templateDefinitionId, int articleId,
string content, string templateDefinitionName, string
templateDefinitionHelpText)
{
this._TemplateDefinitionId = templateDefinitionId;
this.ArticleId = articleId;
this.Content = content;
this.TemplateDefinitionName = templateDefinitionName;
this.TemplateDefinitionHelpText = templateDefinitionHelpText;
}
private int _TemplateDefinitionId;
public int TemplateDefinitionId
{
get { return _TemplateDefinitionId; }
set { _TemplateDefinitionId = value; }
}
private int _ArticleId;
public int ArticleId
{
get { return _ArticleId; }
set { _ArticleId = value; }
}
private string _Content;
public string Content
{
get { return _Content; }
set { _Content = value; }
}
private string _TemplateDefinitionName;
public string TemplateDefinitionName
{
get { return _TemplateDefinitionName; }
set { _TemplateDefinitionName = value; }
}
private string _TemplateDefinitionHelpText;
public string TemplateDefinitionHelpText
{
get { return _TemplateDefinitionHelpText; }
set { _TemplateDefinitionHelpText = value; }
}
}
}
-----------------------------------------------
Here I adds articleAttributes to the Collection, and bind it to a datagrid.
It returns 3 items, all with the same ID and Content... Why??
-----------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
Test.ArticleAttributeCollection ArticleAttributeCollection = new
Test.ArticleAttributeCollection();
Test.ArticleAttribute ArticleAttribute = new Test.ArticleAttribute();
int i = 0;
while (i<2)
{
ArticleAttribute.ArticleId = i;
ArticleAttribute.Content = "Innhold " + i;
ArticleAttributeCollection.Add(ArticleAttribute);
i++;
}
Response.Write(ArticleAttributeCollection.Count);
this.dtgTest.DataSource = ArticleAttributeCollection;
this.dtgTest.DataBind();
}
WHAT IS WRONG IN MY CODE???