473,811 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using CollectionBase


Hello!!

I have created my own collection :

[TypeConverter(t ypeof(MyCollect ionConverter))]
public class MyCollection
{

private Color color1 = Color.White;
private Color color2 = Color.Black;
private int value1 = 0;
private int value2 = 0;
private bool blink = false;
private bool visible = true;
private string nname = string.Empty;

[Browsable(true)]
public Color Color1
{
get { return color1; }
set { color1 = value; }
}

[Browsable(true)]
public Color Color2
{
get { return color2; }
set { color2 = value; }
}

[Browsable(true)]
public int Value1
{
get { return value1; }
set { value1 = value; }
}

[Browsable(true)]
public int Value2
{
get { return value2; }
set { value2 = value; }
}

[Browsable(true)]
public bool Blink
{
get { return blink; }
set { blink = value; }
}

[Browsable(true)]
public bool Visible
{
get { return visible; }
set { visible = value; }
}

[Browsable(true)]
public string Name
{
get { return name; }
set { name = value; }
}

public MyCollection()
{
}
}

public class MyCollectionCon verter : CollectionBase
{
public MyCollectionCon verter ()
{
}

public int Add(MyCollectio ne)
{
return this.InnerList. Add(e);
}

public void AddRange(MyColl ection[] es)
{
this.InnerList. AddRange(es);
}

public void Remove(MyCollec tione)
{
InnerList.Remov e(e);
}

public new void RemoveAt(int index)
{
InnerList.Remov eAt(index);
}

public bool Contains(MyColl ection e)
{
return InnerList.Conta ins(e);
}

public MyCollection this[int index]
{
get { return (MyCollection)t his.InnerList[index]; }
set { this.InnerList[index] = value; }
}
}

and in a click event i add some elements to the collection like this:

MyCollectionCon verter myCollectionCon verter = new MyCollectionCon verter
();

for ( int i = 0; i < 5; i++ )
{
MyCollection myCollection = new MyCollection();
myCollection.Na me = "Element " + i.ToString();

myCollectionCon verter.Add(myCo llection);
}

and then i show myCollectionCon verter in a PropertyGrid, when i open the
Collection editor i can see all the elements.

My question is how can i disable the add and remove buttons in the
Collection editor this because i don't want that a user can add more
elements.

This is possible?

Somebody know how can i do that?

Regards,
Alberto Martinez
*** Sent via Developersdex http://www.developersdex.com ***
Apr 26 '06 #1
2 2144
Juan Martinez wrote:

Hello!!

I have created my own collection :

[TypeConverter(t ypeof(MyCollect ionConverter))]
public class MyCollection
{

private Color color1 = Color.White;
private Color color2 = Color.Black;
private int value1 = 0;
private int value2 = 0;
private bool blink = false;
private bool visible = true;
private string nname = string.Empty;

[Browsable(true)]
public Color Color1
{
get { return color1; }
set { color1 = value; }
}

[Browsable(true)]
public Color Color2
{
get { return color2; }
set { color2 = value; }
}

[Browsable(true)]
public int Value1
{
get { return value1; }
set { value1 = value; }
}

[Browsable(true)]
public int Value2
{
get { return value2; }
set { value2 = value; }
}

[Browsable(true)]
public bool Blink
{
get { return blink; }
set { blink = value; }
}

[Browsable(true)]
public bool Visible
{
get { return visible; }
set { visible = value; }
}

[Browsable(true)]
public string Name
{
get { return name; }
set { name = value; }
}

public MyCollection()
{
}
}

public class MyCollectionCon verter : CollectionBase
{
public MyCollectionCon verter ()
{
}

public int Add(MyCollectio ne)
{
return this.InnerList. Add(e);
}

public void AddRange(MyColl ection[] es)
{
this.InnerList. AddRange(es);
}

public void Remove(MyCollec tione)
{
InnerList.Remov e(e);
}

public new void RemoveAt(int index)
{
InnerList.Remov eAt(index);
}

public bool Contains(MyColl ection e)
{
return InnerList.Conta ins(e);
}

public MyCollection this[int index]
{
get { return (MyCollection)t his.InnerList[index]; }
set { this.InnerList[index] = value; }
}
}

and in a click event i add some elements to the collection like this:

MyCollectionCon verter myCollectionCon verter = new MyCollectionCon verter
();

for ( int i = 0; i < 5; i++ )
{
MyCollection myCollection = new MyCollection();
myCollection.Na me = "Element " + i.ToString();

myCollectionCon verter.Add(myCo llection);
}

and then i show myCollectionCon verter in a PropertyGrid, when i open the
Collection editor i can see all the elements.

My question is how can i disable the add and remove buttons in the
Collection editor this because i don't want that a user can add more
elements.

This is possible?

Somebody know how can i do that?

Regards,
Alberto Martinez
*** Sent via Developersdex http://www.developersdex.com ***

I am guessing here, and I hope it does not stop from someone more knowleable
answering. So my guess is that you may need to add a static variable to
keep track of class level state.

Apr 27 '06 #2
>> My question is how can i disable the add and remove buttons in the
Collection editor this because i don't want that a user can add more
elements. <<

I'm a bit confused by all of this.

You have a class called "MyCollecti on" (which is not a collection, but
an object)
You have a class called MyCollectionCon verter (which is not a
converter, but a collection).
You have a "Collection editor" which you don't explain at all.

Attached to some object is a button click event handle. This leads be
to infer that the "Collection editor " is a WIndows Form with buttons
on it.

Which means that the answer to your question has nothing to do with any
of the code you showed us, and everything to do with the code you did
not.

You want to hide a button. We need to see the button. What the button
does is irrelevant.

Apr 27 '06 #3

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

Similar topics

5
3543
by: Steve M | last post by:
I have subclassed CollectionBase. I have also implemented GetEnumerator(). I have tried to set the DataSource of a DataGrid to an instance of my subclass. However, the items in the grid are not obtained via the Enumerator that I create in the GetEnumerator() method. I have tried elplicitly implementing IEnumerable on my sublass as well. Can anyone help on this? Thanks in advance.
2
1766
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
1
2113
by: alanrn | last post by:
I've implemented a number of strongly-typed collections that inherit from CollectionBase and recently noticed something that I don't fully understand. CollectionBase defines method RemoveAt(). However, CollectionBase implements IList which also defines method RemoveAt(). In my collection when I code my own RemoveAt() method, the compiler issued a warning indicating that my RemoveAt() must be defined with a "new" keyword. So, to keep...
0
2175
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
7096
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
5921
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; }
1
3522
by: Morten Dyndgaard | last post by:
Hi, I want to do the following: I have to XmlSerialize a HashTable, but since it inherits from IDictionary it cannot be XmlSerialized, and I prefer not to make my own implementation of IXmlSerializer. So, I make two arrays, one containing the keys and one containing the values, and I would like to XmlSerialize these arrays. However, the
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:
3
1544
by: myPosts | last post by:
Hi all, I am having class which is derived from collectionbase class. I am adding some string elements to this collection. What i want is to add support of hashing into class which i have derived from collectionbase. Because currently i am adding strings to my collection and at a time of
3
951
by: Tony | last post by:
Hello! I just wonder in .NET 2.0 Generics was added. Before generics existed it was an advantage to get strongly typed methods so we derived collection classes from CollectionBase where we had to implement add remove and so on. But now when generic classes can be used I can't see any point in ever using this CollectionBase any more.
0
9734
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
10652
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
10395
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...
1
10408
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9211
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...
0
6895
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
5561
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...
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3026
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.