collection editor with user control

  • Thread starter simion tishler via .NET 247
  • Start date

S

simion tishler via .NET 247

Hey I have created a collection that inherits from theCollectionsBase that take a columnheader as it's input. I havethen created an intance of the collections class and provided aproperty to it through my usercontrol. The property uses thecollections editor attribute to expose the collections editor atdesign time when I'm using my user control. When I click on thecollections property through the desgner the editor pops up butit only displays a Systems.Object property and not all theproperties of a column header. This is all pretty complex I knowand if I have come this far I should be able to continue. I canbut I just want to take the pain out of it if someone know theanswer.

here is the code for the collection

public class ColumnCollection :System.Collections.CollectionBase
{

public ColumnCollection()
{

}
public void Add(ColumnHeader column)
{
List.Add(column);
}
public void Remove(int index)
{
// Check to see if there is a widget at thesupplied index.
if (index > Count - 1 || index < 0)
// If no widget exists, a messagebox isshown and the operation
// is cancelled.
{
System.Windows.Forms.MessageBox.Show("Index not valid!");
}
else
{
List.RemoveAt(index);
}
}
public ColumnHeader Item(int Index)
{
// The appropriate item is retrieved from theList object and
// explicitly cast to the Widget type, thenreturned to the
// caller.
return (ColumnHeader) List[Index];
}


}

here is the code for the property in the user control

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
,EditorAttribute("typeof(CollectionEditor)","typeof(System.Drawing.Design.UITypeEditor)")]
public ColumnCollection ColumnsCollection
{
get
{
return columnscollection;
}
set
{
columnscollection = value;
}
}
 
Ad

Advertisements

C

Claes Bergefall

1:
Item must be a property, not a method. The collection editor uses
that to determine the type. Also mark it as the default property

2:
Your collection lacks some methods, namely IndexOf, Contains, Insert and
CopyTo. Not sure if that makes a difference for the editor though.

3:
Your Remove method should take a ColumnHeader as input, not
an integer. Currently it does the same thing as RemoveAt.

4:
Make the ColumnCollection property readonly



/claes

Hey I have created a collection that inherits from the CollectionsBase that
take a columnheader as it's input. I have then created an intance of the
collections class and provided a property to it through my usercontrol. The
property uses the collections editor attribute to expose the collections
editor at design time when I'm using my user control. When I click on the
collections property through the desgner the editor pops up but it only
displays a Systems.Object property and not all the properties of a column
header. This is all pretty complex I know and if I have come this far I
should be able to continue. I can but I just want to take the pain out of it
if someone know the answer.

here is the code for the collection

public class ColumnCollection : System.Collections.CollectionBase
{

public ColumnCollection()
{

}
public void Add(ColumnHeader column)
{
List.Add(column);
}
public void Remove(int index)
{
// Check to see if there is a widget at the supplied
index.
if (index > Count - 1 || index < 0)
// If no widget exists, a messagebox is shown and
the operation
// is cancelled.
{
System.Windows.Forms.MessageBox.Show("Index not
valid!");
}
else
{
List.RemoveAt(index);
}
}
public ColumnHeader Item(int Index)
{
// The appropriate item is retrieved from the List
object and
// explicitly cast to the Widget type, then returned to
the
// caller.
return (ColumnHeader) List[Index];
}


}

here is the code for the property in the user control

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
,
EditorAttribute("typeof(CollectionEditor)","typeof(System.Drawing.Design.UIT
ypeEditor)")]
public ColumnCollection ColumnsCollection
{
get
{
return columnscollection;
}
set
{
columnscollection = value;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top