473,788 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CollectionBase Item Member Access

Foundation...Ac cessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #1
6 1849
It's not clear what you're trying to do here. Are you trying to access items
that have been added to a collection class derived from CollectionBase? Or
have you added member variables to the derived class that you're trying to
access?

Could you give some more information?

..ARN.

"DelGator" wrote:
Foundation...Ac cessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #2
It's not clear what you're trying to do here. Are you trying to access items
that have been added to a collection class derived from CollectionBase? Or
have you added member variables to the derived class that you're trying to
access?

Could you give some more information?

..ARN.

"DelGator" wrote:
Foundation...Ac cessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.

How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?

I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.

Thanks in advance...

Nov 17 '05 #3
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow" . I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.de rivedClassPrope rty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #4
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow" . I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.de rivedClassPrope rty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #5
Based on your further explanation, I think that the following may help.

Let's suppose the FileRow class has an integer called fileInt and the
CookieRow class has an int called cookieInt. Suppose the collection class
has a method called DoSomething(). Then you could do something like the
following:

public void DoSomething()
{
foreach( Row r in this )
{
int dRow;
if( r is FileRow )
dRow = ((FileRow)r).fi leInt;
else
dRow = ((CookieRow)r). cookieInt;
}
}

The key here is the if( r is FileRow) statement. This identifies r as in
instance of the FileRow class. Then you use the (odd-looking) cast to get to
the FileRow member field.

I hope this helps.

..ARN.
"DelGator" wrote:
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow" . I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.de rivedClassPrope rty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #6
Based on your further explanation, I think that the following may help.

Let's suppose the FileRow class has an integer called fileInt and the
CookieRow class has an int called cookieInt. Suppose the collection class
has a method called DoSomething(). Then you could do something like the
following:

public void DoSomething()
{
foreach( Row r in this )
{
int dRow;
if( r is FileRow )
dRow = ((FileRow)r).fi leInt;
else
dRow = ((CookieRow)r). cookieInt;
}
}

The key here is the if( r is FileRow) statement. This identifies r as in
instance of the FileRow class. Then you use the (odd-looking) cast to get to
the FileRow member field.

I hope this helps.

..ARN.
"DelGator" wrote:
Sorry...

I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow" . I have also created a "Row" type collection class, based
on CollectionBase.

The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.

I know how to access the derived class members when dealing with simple
base class variables. You would cast...

(FileRow)Row.de rivedClassPrope rty

What I need is the process for accessing them inside the collection.

Hope this is clearer.

Thanks in advance...

Nov 17 '05 #7

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

Similar topics

2
1765
by: m.pollack | last post by:
Hi all, I have an application which uses a class object that contains a collection. In order to use the PropertyGrid control to expose properties to the user at runtime, I created a strongly-typed collection class based on CollectionBase. However, when I use the PropertyGrid to remove objects from the collection at runtime via the popup Object Collection Editor, it appears that the "On*" (CollectionBase.OnRemove and
0
2174
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class and properties derived from this class but will not serialize or deserialize the properties in CollectionBase. Like InnerList, which is a read only property of CollectionBase. How can I serialize and deserialize the InnerList property of...
1
7090
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class and properties derived from this class but will not serialize or deserialize the properties in CollectionBase. Like InnerList, which is a read only property of CollectionBase. How can I serialize and deserialize the InnerList property of...
5
5919
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int Count { get { return 0; }
0
221
by: DelGator | last post by:
Foundation...Accessing derived class members through a variable of their base class is just a matter of casting the variable to the derived class. How would you access the derived class members in a collection of type base class where the collection is derived from CollectionBase? I know that I'm going to feel like a fool when this is resolved, but I have racked my brain, and almost brought down the Google servers, single-handedly,...
3
4588
by: jason | last post by:
Hello. I've got this simple collection populate code I downloaded from the net (sorry can't find source now) I'm trying to test, but I can't seem to get it to work. Any help would be greatly appreciated. I've compiled the following VB.NET into a DLL: Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Collections
1
336
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit down and look at it, I'm wondering why it behaves the way it does, and also how to improve its functionality. First, understand the basic format of a type-safe collection:
1
2905
by: Kyle Novak | last post by:
I have a question about strongly typed objects when looping through a collection based on the CollectionBase object and using a For..Each loop. I have 2 objects: -Invoice: Holds all properties related to an invoice -InvoiceCollection: Inherited from Collectionbase class and holds Invoice objects The InvoiceCollection class is as follows:
8
3931
by: Yuk Tang | last post by:
I am tearing my hair out over this, since I can't see what I'm doing wrong (duh, if I knew, I wouldn't be asking the question). I am adding Field items to a Field Collection, but for some reason it wants to start from the beginning and overwrite all entries before adding the latest member. I've added a couple of msgboxes to illustrate this, one at the add method, another cycling through the collection after the addition has been made. ...
0
9656
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
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
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...
0
8993
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
7517
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
6750
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();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.