Allow User To Add New Property To Class?

Apr 12, 2009

I have created a very basic class for an object that has nothing so far other than a "name" property.

What I want to do is allow the User to add new properties to the class. Basically all the properties will be strings, but I would like to learn how to generally allow the User to create new properties for the class.

View 1 Replies


ADVERTISEMENT

Building Custom User Control - Default Property Of Class?

Jan 22, 2012

If we say blue is the default colour of the Backcolor property I understand it as if you don't specify a colour for Backcolor blue will be its colour. But I could not make sense of default property of a class in the context of building a custom user control. After calling an instance of a class we have to either call one of its members or assign an other object for it. Therefore why should there be a default property?

View 9 Replies

Create A User Control With A List Of Custom Class Type Property

Nov 29, 2011

Is it possible to create a user control with a list of custom class type property? If it is, how can I? The issue is that, in designer mode the property is not displayed in property window. I can add the list on markup but when i switch to the designer mode it gives an error which is 'The user control does not have a public property named BookList'.

View 1 Replies

.net - Make A Class Property Behave Like The Checked Property On RadioButton?

Jun 1, 2012

I have a very simple class that holds a few public properties - ID, Text, Colour, etc. and a Boolean called 'SelectedItem'. Just like the Checked property on RadioButtons, only one item can have its SelectedItem property set to True within a particular group. Note: there will be several separate groups (lists), each allowed to have only one item with SelectedItem = True.

My first thought was that I would probably just have to handle everything outside of the class, setting SelectedItem to False for every other item in a particular list when another item was selected. But that seems rather inelegant to me. So I've been trying to think of how this might be done within the class. For example: could I perhaps have a private string property called say "GroupName" - set in the New sub when adding a new instance of the class - and then use a private shared method to set every item's SelectedItem property to False, provided the item has the same GroupName as the newly selected item? I would have a go at doing this but I have no idea how to enumerate every instance of a class from within that class, or whether that's even possible. Is it? Or is there another (better) way to achieve my goal? Here is a cut-down version of what I've got so far:

Public Class ResourceItem
Public ID As Integer
Public Text As String[code]....

As can be seen: instead of instantiating a new ResourceItem and passing that as an argument to the manager's Add procedure, I'm simply passing the details of the new item and the procedure is creating the item from those. I don't know whether this is a good or bad idea - please advise - but I've done it because I couldn't figure out how to make the SelectedItem property only writeable by the manager, so I wanted to avoid having directly accessible objects that could have their SelectedItem property set to True without it deselecting all the other items in the same group. Of course that still leaves the possibility of setting a variable to one of the manager's list items and setting it from there, so I would still like to know how I could prevent that, if possible.

UPDATE: I didn't use the code above in the end, deciding instead to go with Cyborgx37's solution - which seems to work perfectly well for me despite the warnings about best practice. I also realised I would need to use the same class in another scenario where multiple items could be selected, so it was easy to add a Boolean property to the manager to enable that.

View 2 Replies

Error - In Order To Evaluate An Indexed Property, The Property Must Be Qualified And The Arguments Must Be Explicitly Supplied By The User

Jun 20, 2012

I'm having a few problems converting some code into VB.NET from C#. Most of the translating is done, but I am getting errors when I try to run my code, and I can't figure out what is causing them. Here is the Sub I translated.

Public Sub CreateWidget()
Dim blue As LCDColor
blue.Red = 0
blue.Green = 0

[code]....

The error I receive on this line ("vision.Widgets.CreateWidget(wg1)") reads "In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user."

View 11 Replies

VB SQL Incorrect Syntax Near '' - In Order To Evaluate An Indexed Property The Property Must Be Qualified And The Arguments Must Be Explicitly Supplied By The User

Jun 6, 2009

I receive a System.Data.SqlClient.SqlException in the following code: Specifically Incorrect syntax near ' In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user. The exception detail in its entirety is shown below the code.

[Code]...

View 5 Replies

Having A Class Property Dependent On Another Property Opinion?

Aug 13, 2009

I have the following code:

Public Class MyColorsClass
'Constructors
Public Sub New()
'Empty Constructor

[code]....

However, if the empty constructor was called to instatiate this class then the colortype is not yet set. Therefore, if one accesses the 'IsColorCool' property it will always return 'False'. Now for the sake of this example, I must keep the empty constructor as part of the class.Now I could add some code in the 'IsPropertyCool' to check and see if a ColorType has been defined, and throw an exception if it has not been set, but I don't really want to do that.I also could always move the logic OUT of the property and into a method on the class called 'DefineIfColorIsCool' or something, and make the owness on the caller to make sure the method was called if they want to use the property 'IsColorCool'?

View 5 Replies

.net - Suppress A Property Or Method From A Base-class In A Derived Class?

Apr 7, 2011

Supose a base class

Public Class airplane
Private var_num_seats As Integer
Private var_num_engines As Integer

[code]....

Obviously, I don't wish that the class Glider has the method "start_engines" neither the property "num_engines". Otherwise, other child classes may have. How can I supress these property and method in child class, not just ignoring (if I can)?

View 2 Replies

Can't Set DataTable Class Level Variable = Class Table Property?

Sep 29, 2011

I have procedure (Import) that calls a for a new instance of frmImportData. I also have a class name clsBatch that has a data table property called prpParametersTable.For some reason, I get an error (indicated below with ERROR>>>) when trying to assign prpParameterTable to cv_dtImport2. The error states "Object reference not set to an instance of an object.". Why does this error not happen when I assign dtBP to cv_dtImport1? Both cv_dtImport1 and cv_dtImport2 are equal to Nothing and in my Import procedure dtBP = prpParametersTable.

Public Sub Import(ByVal clsB As clsBatch)
Try
Me.cv_clsB = clsB

[code]....

View 5 Replies

Class Property Usage - Unable To Retrieve A Variable From On Class

Nov 14, 2009

I have three class files, accounts.vb and transactions.vb in addition to my form.vb. I am unable to retrieve a member variable from on class from inside the other. When the combobox index changes, the program loads the correct account (checking or saving) from two different sequential files. I don't think I have the calcBalance procedure in the correct class file. And that is what I am having trouble with. Accessing it to display it. [Code]

View 1 Replies

Access Members Of A Sub Class Through A Property Of The Parent Class?

Mar 30, 2010

This is a bit of a continuation from a previous post for which AtmaWeapon was very informative.

Problem:
A parent class has a sub class with various properties. A property of the parent class is a List(of T) with T = the sub class The issue is how to store data in the sub class of the instantiated parent

Some example code (hopefully formatted correctly):

Code:
'=========== Class Definitions =============
Public Class courseClass
Public Class timeTableClass

[Code].....

View 7 Replies

Adding A List (of Class) Or Collection As Another Class's Property

Apr 2, 2010

I'm looking for a tutorial on how to Adding a list(of Class) or Collection as another Class's Property.What I am after is something like the Columns Collection for the DatagridView control.I would like to add Items in the graphics screen. Where the item list is displayed in the left panel and the selected Item properties are displayed in the right panel.

View 4 Replies

.net - Accessing Property Of A Class Without Inherting The Class

Apr 7, 2012

I have a class that has the following property that is generated by the methods in the constructor.

Public Class clsLoadTables
Private _ds As New DataSet
Public Property ds() As DataSet
Get

[CODE]........................

My problem is that I do not want to inherit this class, but I have other classes that need to access the ds DataSet property. If at all possible I would like to not use inheritance and not load my datatable more than once in the program.

Here is my failed attempt to access the property inside another class that is not inheriting clsLoadTables:

[CODE].........................

How I can access this dataset that I want to load only once in the program from many classes without using class inheritance or a global module?

View 3 Replies

VS 2005 Class Contain Another Class Within It - Interface And Property?

Jul 29, 2010

I know that an interface can contain another interface within it.But;can a class contain another class within it?Can an interface contain another interface within it?

View 9 Replies

Class Array As Another Class Property?

Jul 28, 2010

I have two classes, and for a property in one of the classes I'd like to be able to load it up with an array of the other class. However my attempt at accomplishing this results in a "Object reference not set to an instance of an object" error. I know it's a rookie mistake, but I'm stumpedssist?

My code is as follows:
Namespace Parking
Public Class garage

[code]......

View 2 Replies

"upgrade" An Object To An Inherited Class, And Keep All The Base Class's Property Values?

Jul 5, 2010

bare with me during this silly example. :-) Let's say I have a class like this:

Public Class Animal
Public iLegs as int32 ' Number of legs
Public bWings as Boolean ' Wings? Yes/No
End Class

And another class that inherits the "Animal" class and adds one more property:

Public Class ScaryAnimal
Inherits Animal
Public iScariness as int32 ' 0-100, how scary is it?
End Class

Now, if I have an instance of "Animal" with some values in it, and I decide I want to cast it to a ScaryAnimal for some reason, how do I do that without having to create a new instance of "ScaryAnimal" and copy each property value?Basically I'm looking for a way to do this, without having to write the lines marked with '*** below:

[Code]...

View 2 Replies

Class Property In For Each?

Jun 15, 2010

I am running from a problem while iterating over class properties.

I have my first class:

class Item
private _UIN as integer = 0
private _Name as string = ""

[Code]....

I get UIN, Name, ItemCategory but i expected UIN, Name and Category.

I am a bit unclear about this and dun know why this is happening? What should i do to correct it?

View 1 Replies

Get Property From A Different Class?

May 26, 2010

I have 2 classes and I set a property in class A... how can I get this value within Class B?[code]...

View 3 Replies

Get The Name Of A Class Property?

Jun 25, 2011

How can I get a string with the name of a property at run time?Obviously using GetProperty, as shown below, is NOT a solution since it requires knowing the property name to begin with:

Imports System.Reflection
Module Module1
Public Class Country
Public Property Capital As String
Public Property Population As Long

[Code]...

What I want is to get the name from an instance (Nation.Capital for example) or from the type (Country.Capital).

View 6 Replies

Access Property In A Class?

Aug 27, 2011

Private _Order As Order() Public Property Order() As Order() Get Return _Order End Get Set(ByVal value As Order()) _Order = value End Set End Property

I need to get property name 'color' inside the 'order()' array, i am trying ' Order.color ' but its not getting,

View 4 Replies

Advantage Of Using Property's In Class?

May 18, 2011

I have the following class:

Class MyClass
Property MyInteger as Integer
Set(ByVal value as Integer)
_MyInteger = value

[code]....

As I'm not using any validation etc in my Property, is there any advantage of using a Property in this case, or would it be neater to use:

Class MyClass
Public MyInteger as Integer
End Class

View 5 Replies

Class Property Specifying An Object?

Mar 9, 2012

I'm currently writing a HMI for an automated machine in VB.Net 2010. I have a custom class that turns a Border green or red depending on the value of an input on a remote I/O module.

The connection to the remote I/O module is through a COM object provided by the manufacturer. I have three remote connections, lets' call them g1, g2, and g3. They're of type Manufacturer.ConnectionObject.

I would like to specify, using a property that I can set in XAML, that instances of MyCustomBorder use g1, g2, or g3. Unfortunately, setting up a Property called g and typing 'g1' into the property field results in the message "Property value is not valid. Details: Property 'g' does not support String to Value conversion."

[code...]

I need to implement a converter between String and the custom class, Manufacturer.ConnectionObject, but I have no idea how to accomplish this, especially since Manufacturer.ConnectionObject is part of a closed-to-me COM object.

View 2 Replies

Create A Property In A .NET Class?

Dec 3, 2008

When you create a property in a VB.NET class how do you tell it which category it will belong to when it shows up in the property window?

View 4 Replies

Have Generics In A Class Property?

Jul 28, 2010

I have a Class that is defined as

Public MustInherit Class Entity(Of T As Entity(Of T))

And various classes derived from it. I would like to have another class accept all of the derived objects as a property, but I cannot seeem to find a workable syntax. If it were a parameter of a sub, I could say

Public Sub Foo(T As Entity(Of T))(TheEntity As T)

I can't seem to get that to work for a property:

Public Property E(Of Entity(Of T))() As Entity(Of T)

Gives me "Type parameters cannot be specified on this declaration"

Public Property E() As Entity2008(Of T)

Gives me "Type Parameter T does not inherit from or implement the constraint type ..."Is there an acceptable way to do this or am I stuck with using a Set Sub and a Get Function?

View 2 Replies

How To Call Property Value From Another Class

Oct 15, 2011

have inherited a Datagridview column called DatagridviewNumBoxColumn, I have added a property called FormatStringMy question is i want to access the property of format string value from another class.

Public Class DataGridViewNumBoxColumn
nherits DataGridViewColumn
Public m_FormatString As String

[code]....

View 1 Replies

Se An Arraylist As A Property In Class?

Jul 12, 2009

I am trying to use an arraylist as a property in my class, but I am getting an error when I try to set it in my main code. Is my syntax correct?

Public Class ControlSender
Private _NodeList As ArrayList
Public Property NodeList() As ArrayList

[code].....

View 1 Replies

Set Initial Value Of A Property In A Class?

Jun 2, 2012

If I place it on the form, I want to have the text as the name of the control, like label1, label2, etc.[code]...

View 1 Replies

Use Alias Name For Property Of Class?

Apr 21, 2010

I am assigning the class object to grid's data source. And grid displaying all the properties of class with values. But i do not want to display the original name of properties of class. Is there any way to provide set alias name to property to display in grid?

I know that it can be possible by setting the grid's column caption. But i want to do it at class level or by other way instead of processing on Grid. Is there any attribute that set alias name to property?

View 7 Replies

Using Class As Datatype In Property?

Dec 17, 2010

I am getting error in the line

MySrs(1).A=10

It is probably that I havenot created an instance of class, MyPoint.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MySrs As New MySeries(20)
MySrs(1).A = 10

[code]....

View 3 Replies

.net - Get A Class Property To Be A List Array?

Oct 14, 2009

Stack Overflowers:I have been racking my brain trying to get an List(of T) type array to be the property of a class. I know there has to be a simple way of doing it and I can't find a good example on google. Everytime I create a class that I think will work I get the "Object reference not set to an instance of an object" error when I try to use it. My thinking now is that I cannot use it in the way I was hoping to. Here is my latest attempt:

Public Class Item
Private _itemno As String
Public Property ItemNo() As String
Get

[code]....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved