Make A Class Property An Enumerated Value?

May 4, 2010

Imports Microsoft.VisualBasic
Public Class DealSlot
Private mSlotType As String
[Code]...

View 6 Replies


ADVERTISEMENT

Dynamic Enumerated Property Of User Control?

Mar 27, 2009

I am using VB 2008 Express edition.I have created a user control that has an enumerated property like:Public

[Code]...

There are 3 alternatives for this property: Member0, Member1 and Member2.Is it possible to change the alternative values of this property in runtime dynamically?

View 7 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

LINQ Query Is Enumerated - Turn On Some Kind Of Flag That Alerts Me Each Time A LINQ Query Is Enumerated?

Sep 22, 2009

I know that LINQ queries are deferred and only executed when the query is enumerated, but I'm having trouble figuring out exactly when that happens.Certainly in a For Each loop, the query would be enumerated.What's the rule of thumb to follow? I don't want to accidentally enumerate over my query twice if it's a huge result.

For example, does System.Linq.Enumerable.First enumerate over the whole query? I ask for performance reasons. I want to pass a LINQ result set to an ASP.NET MVC view, and I also want to pass the First element separately. Enumerating over the results twice would be painful.It would be great to turn on some kind of flag that alerts me each time a LINQ query is enumerated. That way I could catch scenarios when I accidentally enumerate twice.

View 3 Replies

ICloneable - Make A Deep Copy By Adding A Clone Property To Class?

Feb 6, 2012

I am trying to make a deep copy by adding a clone property to my class.

[Code]...

View 1 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

Query Results Cannot Be Enumerated More Than Once?

Oct 5, 2011

I have the following code in my program: Dim empenrollments = From enroll In db.EnrollmentSummary(eid)

Select New With {.Name = ename, enroll} Dim elist = empenrollments.ToList returns this error

In the following lines, I have to get each row in the returned results and add it to a DataTable, but it never gets there.

[Code]...

View 4 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

VS 2008 Enumerated Controls An Array Of Panels?

Aug 13, 2009

I'm working on an menu program right now which has 20 panels used to display bmps that can be clicked on to select things. These panels are simply named something like pnl01, pnl02, etc. to pnl20. I'd like to make them into an array, like pnl(0) through pnl(19), so i can change the bmp on different panels like this:

x = 7
pnl(x).backgroundimage = image.fromfile(file)

i thought this had something to do with enumerated controls but after some searching i couldn't figure out if i was looking for the right thing.

View 3 Replies

IDE :: Make A Property In A Property Grid A List Box In 2010?

Feb 21, 2011

I have the following property in a property grid in VB.Net 2010.

<Description("Rapid Entry Post Car Wash Settings CarWashOptionPushButtons"), _
Category("Post Car Wash")> _
Public Property CarWashOptionPushButtons() As String

[code]....

I need to make this property a list box that gets the values from a database table and populates the list box with the values from the table. I have tried numerous things to no avail.

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

Clean (lossless) Looping Of Flagged Enumerated Types?

Nov 18, 2009

I've noticed something in vb that is rather disconcerting, and now i'm trying to find if there is a way around id. Given the nature of enumerated types, they are more or less substitutes for named values, usually grouped in some sensible manner for readability as well as other things. Now, .Net added the FlagsAttribute() for affecting a Enumerated type so that it can reference multiple values (bit flags) for additional support. (Basically it is easier to say If MyEnum And MyFlag as opposed to if MyNum and 65536) However, sometimes we just want to cycle through our enumerated values For x = 0 to N Next I've noticed that with Enumerated types, it is ever so annoying in two folds:

A) Dim X as MyEnumType = 8 '<- Causes a Type Error : Cannot implicitly convert Integer to MyEnumType

B)
For X as MyEnum = MyEnum.Lowest to MyEnum.Highest
Console.Writeline(Ctype(x, integer))
Next

[code]....

However, as per usual, VB cheats, and performs the latter (violating VB's own Strict Typing rules) and thus if I have 8 enumerated values, each representing a Bit value from 1 to 256, How can I smoothly (with not extraneous executions) run the loop from lowest to highest. (now of course this is bitwise, so i could do a while loop with a << operator, but let us just assume we don't know the values of all the Enumerated elements, we just know they aren't sequential (+1)). I want a loop that ONLY executes the ACTUAL elements of an enumerated type, nothing in between their intrinsic values.

View 2 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

Can't Make Difference Between Public Class And Private Class And Friend And Protected Friend Class

May 15, 2009

I can't make difference between public class and private class and friend and protected friend class.

View 1 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

Make Class Array Inside Class

Feb 28, 2012

I am New to <acronym title="Visual Basic">Vb</acronym>.Net. this is my first test. i try to create small address book. but i don't know what wrong. it compile perfect but when it run it give error and not work. is there any other way to add same class like in class inside array?

[Code]...

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

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

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







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