473,574 Members | 5,835 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Expose Count from System.Collecti ons.CollectionB ase in an inherited class

I'm trying to count how many items are in a dynamic collection. This is
the
code I have so far.

*** Begin Code ***
Public Class Rule
Private _rulevars As RuleVarsCollect ion
Private _rulename As String
Public Property Name() As String
Get
Return _rulename
End Get
Set(ByVal value As String)
_rulename = value
End Set
End Property
Public Property VariablesList() As RuleVarsCollect ion
Get
Return _rulevars
End Get
Set(ByVal value As RuleVarsCollect ion)
_rulevars = value
End Set
End Property
Public Overrides Function ToString() As String
Return Name.ToString
End Function
Public Sub New(ByVal RuleName As String)
'initialize local variables
_rulevars = New RuleVarsCollect ion()
_rulename = RuleName
End Sub
End Class
Public Class RuleVar
'define the Variable class here
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
End Class
Public Class RuleVarsCollect ion
Inherits System.Collecti ons.CollectionB ase
Public Sub Add(ByVal Var1 As RuleVar)
List.Add(Var1)
End Sub
Public Sub Remove(ByVal index As Integer)
'Check to see if there is an item at the supplied index.
If index Count - 1 Or index < 0 Then
System.Windows. Forms.MessageBo x.Show("Index not Valid!")
Else
List.RemoveAt(i ndex)
End If
End Sub
Default Public ReadOnly Property item(ByVal index As Integer) As
RuleVar
Get
Return CType(List.Item (index), RuleVar)
End Get
End Property
End Class
*** End Code ***

I want to display how many objects are in the collection when it is
selected
from a listbox

*** Begin Code ***
Private Sub ListBox2_Select edIndexChanged( ByVal sender As
System.Object,
ByVal e As System.EventArg s) Handles ListBox2.Select edIndexChanged
Dim r1 As Rule
r1 = Me.ListBox2.Sel ectedItem
MsgBox("Number of items in collection: " & CStr(r1.Count))
End Sub
*** End Code ***

I've been told that I need to expose Count in the inherited class, but
I
don't know how or where to do that. I'm very green.

Thanks,
Blake

Jul 20 '06 #1
2 2165
Blake,

Rule is a base class, not an inherited class. What are you trying to count
when you say r1.Count?

Classes that inherit from CollectionBase already have a Count property, so
there is no need to expose it.

Are you trying to get r1.VariablesLis t.Count? That should work "out of the
box".

Kerry Moorman


"GoCoogs" wrote:
I'm trying to count how many items are in a dynamic collection. This is
the
code I have so far.

*** Begin Code ***
Public Class Rule
Private _rulevars As RuleVarsCollect ion
Private _rulename As String
Public Property Name() As String
Get
Return _rulename
End Get
Set(ByVal value As String)
_rulename = value
End Set
End Property
Public Property VariablesList() As RuleVarsCollect ion
Get
Return _rulevars
End Get
Set(ByVal value As RuleVarsCollect ion)
_rulevars = value
End Set
End Property
Public Overrides Function ToString() As String
Return Name.ToString
End Function
Public Sub New(ByVal RuleName As String)
'initialize local variables
_rulevars = New RuleVarsCollect ion()
_rulename = RuleName
End Sub
End Class
Public Class RuleVar
'define the Variable class here
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
End Class
Public Class RuleVarsCollect ion
Inherits System.Collecti ons.CollectionB ase
Public Sub Add(ByVal Var1 As RuleVar)
List.Add(Var1)
End Sub
Public Sub Remove(ByVal index As Integer)
'Check to see if there is an item at the supplied index.
If index Count - 1 Or index < 0 Then
System.Windows. Forms.MessageBo x.Show("Index not Valid!")
Else
List.RemoveAt(i ndex)
End If
End Sub
Default Public ReadOnly Property item(ByVal index As Integer) As
RuleVar
Get
Return CType(List.Item (index), RuleVar)
End Get
End Property
End Class
*** End Code ***

I want to display how many objects are in the collection when it is
selected
from a listbox

*** Begin Code ***
Private Sub ListBox2_Select edIndexChanged( ByVal sender As
System.Object,
ByVal e As System.EventArg s) Handles ListBox2.Select edIndexChanged
Dim r1 As Rule
r1 = Me.ListBox2.Sel ectedItem
MsgBox("Number of items in collection: " & CStr(r1.Count))
End Sub
*** End Code ***

I've been told that I need to expose Count in the inherited class, but
I
don't know how or where to do that. I'm very green.

Thanks,
Blake

Jul 20 '06 #2
It does. I noticed so after I made the post. I must have been doing
something different before.

Kerry Moorman wrote:
Blake,

Rule is a base class, not an inherited class. What are you trying to count
when you say r1.Count?

Classes that inherit from CollectionBase already have a Count property, so
there is no need to expose it.

Are you trying to get r1.VariablesLis t.Count? That should work "out of the
box".

Kerry Moorman


"GoCoogs" wrote:
I'm trying to count how many items are in a dynamic collection. This is
the
code I have so far.

*** Begin Code ***
Public Class Rule
Private _rulevars As RuleVarsCollect ion
Private _rulename As String
Public Property Name() As String
Get
Return _rulename
End Get
Set(ByVal value As String)
_rulename = value
End Set
End Property
Public Property VariablesList() As RuleVarsCollect ion
Get
Return _rulevars
End Get
Set(ByVal value As RuleVarsCollect ion)
_rulevars = value
End Set
End Property
Public Overrides Function ToString() As String
Return Name.ToString
End Function
Public Sub New(ByVal RuleName As String)
'initialize local variables
_rulevars = New RuleVarsCollect ion()
_rulename = RuleName
End Sub
End Class
Public Class RuleVar
'define the Variable class here
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
End Class
Public Class RuleVarsCollect ion
Inherits System.Collecti ons.CollectionB ase
Public Sub Add(ByVal Var1 As RuleVar)
List.Add(Var1)
End Sub
Public Sub Remove(ByVal index As Integer)
'Check to see if there is an item at the supplied index.
If index Count - 1 Or index < 0 Then
System.Windows. Forms.MessageBo x.Show("Index not Valid!")
Else
List.RemoveAt(i ndex)
End If
End Sub
Default Public ReadOnly Property item(ByVal index As Integer) As
RuleVar
Get
Return CType(List.Item (index), RuleVar)
End Get
End Property
End Class
*** End Code ***

I want to display how many objects are in the collection when it is
selected
from a listbox

*** Begin Code ***
Private Sub ListBox2_Select edIndexChanged( ByVal sender As
System.Object,
ByVal e As System.EventArg s) Handles ListBox2.Select edIndexChanged
Dim r1 As Rule
r1 = Me.ListBox2.Sel ectedItem
MsgBox("Number of items in collection: " & CStr(r1.Count))
End Sub
*** End Code ***

I've been told that I need to expose Count in the inherited class, but
I
don't know how or where to do that. I'm very green.

Thanks,
Blake
Jul 20 '06 #3

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

Similar topics

5
5908
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; }
5
1424
by: Hoang Do | last post by:
I have a curious question and I am sure someone else must have run into it before. Is it a problem with the collections class or am I misunderstanding the keyword "Overide". why does this compile: ---------------------------------------------------- using System; class test {
2
1561
by: maxim | last post by:
Hi, I have a Class in C# that exposes property from System.Uri type. I want to access this property from classic Visual Basic. public class TestClass {
6
2724
by: Bern McCarty | last post by:
I'm trying to use the VS 2005 March Tech Preview and am trying to adjust some MC++ to the new C++/CLI syntax. I got a little hung up when I encountered the below error. Certainly my 'Bentley::Mstn::Element' type derives ultimately from System::Object. It is a ref class. And upcasting is always implicit right? So I don't understand why I'm...
3
4581
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...
1
1240
by: BB | last post by:
Hey, CollectionBase has following methods OnInsertComplete,OnSetComplete,.... When I bind a collection to a datagrid. Is it the datagrid thats call the OnInsertComplete? Or is it the List.Add thats calling the OnInsertComplete? What I don't understand is when OnSetComplete is called
2
3715
by: Ian Gore | last post by:
Hi, I'm relatively new to VB.NET so I'd be grateful if someone could point out what I don't understand here... 1) Creating a strongly typed collection by inheriting CollectionBase. This is covered in most of the books I've read. Basically you inherit CollectionBase and then add methods (say Add) that takes your types as a parameter and...
1
2896
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...
1
1234
by: Ian Ashworth | last post by:
Id like to be able to set a new instance of the EposTransaction class and add Sale items to the Sales collection via EposTransaction.Sales.Add(SaleItem). Basically want all the functionality of the Sales collection class exposed within my Transaction class. I'm new to .net from a classic vb background so any help would be greatly...
0
7739
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...
0
8083
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. ...
0
8258
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...
1
7835
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...
0
6487
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...
1
5635
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...
0
5326
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...
0
3761
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...
1
1360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.