473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Using CollectionBase


Hello!!

I have created my own collection :

[TypeConverter(typeof(MyCollectionConverter))]
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 MyCollectionConverter : CollectionBase
{
public MyCollectionConverter ()
{
}

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

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

public void Remove(MyCollectione)
{
InnerList.Remove(e);
}

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

public bool Contains(MyCollection e)
{
return InnerList.Contains(e);
}

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

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

MyCollectionConverter myCollectionConverter = new MyCollectionConverter
();

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

myCollectionConverter.Add(myCollection);
}

and then i show myCollectionConverter 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 2126
Juan Martinez wrote:

Hello!!

I have created my own collection :

[TypeConverter(typeof(MyCollectionConverter))]
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 MyCollectionConverter : CollectionBase
{
public MyCollectionConverter ()
{
}

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

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

public void Remove(MyCollectione)
{
InnerList.Remove(e);
}

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

public bool Contains(MyCollection e)
{
return InnerList.Contains(e);
}

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

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

MyCollectionConverter myCollectionConverter = new MyCollectionConverter
();

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

myCollectionConverter.Add(myCollection);
}

and then i show myCollectionConverter 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 "MyCollection" (which is not a collection, but
an object)
You have a class called MyCollectionConverter (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
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...
2
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...
1
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(). ...
0
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...
1
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...
5
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...
1
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...
1
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...
3
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...

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.