473,499 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with a Custom Control.. passing Objects to a Collection

Trying to figure out how to replicate the same interface as what a
ListView control has.

I have everything working for the most part, with exception of 1 minor
setback.

I can't seem to pass the "ListViewItem" object to a Collection on
"MyControl".
- - - - - -
Breakdown:
- - - - - -
============
ControlItem
============

I have the ListViewItem (object) called ControlItem for use in
"MyControl".

To keep things simple, I made the ControlItem a separate class DLL.

I can declare the ControlItem object.
I can set the "Text" property.
I can set the object.SubItem.Add("parameter").

==========
MyControl
==========
private ControlItemCollection _Items = null;
public class ControlItemCollection
{
private ArrayList _CollectionItems = null;
string strTemp = "";

public ControlItemCollection this [int index]
{
get
{
return (ControlItemCollection)_CollectionItems[index];
}
}

public ControlItemCollection()
{
_CollectionItems = new ArrayList();
}

public void Add(ControlItem controlItem)
{
_CollectionItems.Add(controlItem);
}
}
//
// Notes:
// In an ideal declaration, this is how I would declare it:
//

public ControlItemCollection Items
{
set
{
_Items.Add((ControlItem)value);
}

get
{
return _Items;
}
}

//
// However, it comes back during compile time stipulating:
// Cannot implicitly convert type
'MyControl.myLV.ControlItemCollection' to 'ControlItems.ControlItem'
// It makes sense though. The 'Items' is declared as
'ControlItemCollection'.
//
- - - - - - - - - -
Analysis of Design
- - - - - - - - - -

I won't bore you with the in depth details, unless you need more info.
Trying to keep this short and simple.

Once you create a ListViewItem object and try to add it to the
control:

lvSample.Items.Add(oItem);

If you stop at the ".Add" portion you will see the path:

System.Windows.Forms.ListViewItem
ListViewItemCollection.Add(System.Windows.Forms.Li stViewItem value)(+2
overloads)

When I first started tinkering around with this, I used the following
code:
==========
MyControl
==========

public ControlItemCollection Items
{
set
{
_Items.Add(value.ToString());
}

get
{
return _Items;
}
}

public class ControlItemCollection
{
...

public void Add(string text)
{
}
}
And noticed when I executed the code:

lvMyControl.Items.Add(oItem);

If you stop at the ".Add" portion you would have seen the path:

void ControlItemCollection.Add(string text)

So tinkering around I made the following changes:

==========
MyControl
==========

public class ControlItemCollection
{
...

public ControlItem Add(string text)
{
return (new ControlItem());
}
}

And noticed that when you stop at the ".Add" portion you now see:

ControlItems.ControlItem ControlItemCOllection.Add(string text)

It's close, but I still run into the snag of the "ControlItem" object
being passed to the Collection reference that is defined by "Items".


I think the required changes would be something like:

==========
MyControl
==========

public class ControlItemCollection
{
...

public ControlItem Add(ControlItem controlItem)
{
return controlItem;
}
}

But I'm not really sure how to piece it all together, so the
'ControlItem' object is passed and added to the Master collection that
resides within the Control itself.

If anyone can help me out with this complexity.. my hats off to ya.
Nov 15 '05 #1
2 1389
Your indexer is returning a ControlItemsCollection type and should also be
read-write.

--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Cider123" <ci******@hotmail.com> wrote in message
news:55**************************@posting.google.c om...
Trying to figure out how to replicate the same interface as what a
ListView control has.

I have everything working for the most part, with exception of 1 minor
setback.

I can't seem to pass the "ListViewItem" object to a Collection on
"MyControl".
- - - - - -
Breakdown:
- - - - - -
============
ControlItem
============

I have the ListViewItem (object) called ControlItem for use in
"MyControl".

To keep things simple, I made the ControlItem a separate class DLL.

I can declare the ControlItem object.
I can set the "Text" property.
I can set the object.SubItem.Add("parameter").

==========
MyControl
==========
private ControlItemCollection _Items = null;
public class ControlItemCollection
{
private ArrayList _CollectionItems = null;
string strTemp = "";

public ControlItemCollection this [int index]
{
get
{
return (ControlItemCollection)_CollectionItems[index];
}
}

public ControlItemCollection()
{
_CollectionItems = new ArrayList();
}

public void Add(ControlItem controlItem)
{
_CollectionItems.Add(controlItem);
}
}
//
// Notes:
// In an ideal declaration, this is how I would declare it:
//

public ControlItemCollection Items
{
set
{
_Items.Add((ControlItem)value);
}

get
{
return _Items;
}
}

//
// However, it comes back during compile time stipulating:
// Cannot implicitly convert type
'MyControl.myLV.ControlItemCollection' to 'ControlItems.ControlItem'
// It makes sense though. The 'Items' is declared as
'ControlItemCollection'.
//
- - - - - - - - - -
Analysis of Design
- - - - - - - - - -

I won't bore you with the in depth details, unless you need more info.
Trying to keep this short and simple.

Once you create a ListViewItem object and try to add it to the
control:

lvSample.Items.Add(oItem);

If you stop at the ".Add" portion you will see the path:

System.Windows.Forms.ListViewItem
ListViewItemCollection.Add(System.Windows.Forms.Li stViewItem value)(+2
overloads)

When I first started tinkering around with this, I used the following
code:
==========
MyControl
==========

public ControlItemCollection Items
{
set
{
_Items.Add(value.ToString());
}

get
{
return _Items;
}
}

public class ControlItemCollection
{
...

public void Add(string text)
{
}
}
And noticed when I executed the code:

lvMyControl.Items.Add(oItem);

If you stop at the ".Add" portion you would have seen the path:

void ControlItemCollection.Add(string text)

So tinkering around I made the following changes:

==========
MyControl
==========

public class ControlItemCollection
{
...

public ControlItem Add(string text)
{
return (new ControlItem());
}
}

And noticed that when you stop at the ".Add" portion you now see:

ControlItems.ControlItem ControlItemCOllection.Add(string text)

It's close, but I still run into the snag of the "ControlItem" object
being passed to the Collection reference that is defined by "Items".


I think the required changes would be something like:

==========
MyControl
==========

public class ControlItemCollection
{
...

public ControlItem Add(ControlItem controlItem)
{
return controlItem;
}
}

But I'm not really sure how to piece it all together, so the
'ControlItem' object is passed and added to the Master collection that
resides within the Control itself.

If anyone can help me out with this complexity.. my hats off to ya.

Nov 15 '05 #2
Just to clarify. The indexer should be:

public ControlItem this [int index]
{
get
{
return (ControlItemCollection)_CollectionItems[index];
}
set{_CollectionItems[index]=value;}
}

Oh and I guess it would help loads if your class was actually a collection
based on, say, CollectionBase. It implements IEnumerable and all sorts of
good stuff.

The collection base class has an internal List member too so you don't need
to define the _CollectionItems.
--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Cider123" <ci******@hotmail.com> wrote in message
news:55**************************@posting.google.c om...
Trying to figure out how to replicate the same interface as what a
ListView control has.

I have everything working for the most part, with exception of 1 minor
setback.

I can't seem to pass the "ListViewItem" object to a Collection on
"MyControl".
- - - - - -
Breakdown:
- - - - - -
============
ControlItem
============

I have the ListViewItem (object) called ControlItem for use in
"MyControl".

To keep things simple, I made the ControlItem a separate class DLL.

I can declare the ControlItem object.
I can set the "Text" property.
I can set the object.SubItem.Add("parameter").

==========
MyControl
==========
private ControlItemCollection _Items = null;
public class ControlItemCollection
{
private ArrayList _CollectionItems = null;
string strTemp = "";

public ControlItemCollection this [int index]
{
get
{
return (ControlItemCollection)_CollectionItems[index];
}
}

public ControlItemCollection()
{
_CollectionItems = new ArrayList();
}

public void Add(ControlItem controlItem)
{
_CollectionItems.Add(controlItem);
}
}
//
// Notes:
// In an ideal declaration, this is how I would declare it:
//

public ControlItemCollection Items
{
set
{
_Items.Add((ControlItem)value);
}

get
{
return _Items;
}
}

//
// However, it comes back during compile time stipulating:
// Cannot implicitly convert type
'MyControl.myLV.ControlItemCollection' to 'ControlItems.ControlItem'
// It makes sense though. The 'Items' is declared as
'ControlItemCollection'.
//
- - - - - - - - - -
Analysis of Design
- - - - - - - - - -

I won't bore you with the in depth details, unless you need more info.
Trying to keep this short and simple.

Once you create a ListViewItem object and try to add it to the
control:

lvSample.Items.Add(oItem);

If you stop at the ".Add" portion you will see the path:

System.Windows.Forms.ListViewItem
ListViewItemCollection.Add(System.Windows.Forms.Li stViewItem value)(+2
overloads)

When I first started tinkering around with this, I used the following
code:
==========
MyControl
==========

public ControlItemCollection Items
{
set
{
_Items.Add(value.ToString());
}

get
{
return _Items;
}
}

public class ControlItemCollection
{
...

public void Add(string text)
{
}
}
And noticed when I executed the code:

lvMyControl.Items.Add(oItem);

If you stop at the ".Add" portion you would have seen the path:

void ControlItemCollection.Add(string text)

So tinkering around I made the following changes:

==========
MyControl
==========

public class ControlItemCollection
{
...

public ControlItem Add(string text)
{
return (new ControlItem());
}
}

And noticed that when you stop at the ".Add" portion you now see:

ControlItems.ControlItem ControlItemCOllection.Add(string text)

It's close, but I still run into the snag of the "ControlItem" object
being passed to the Collection reference that is defined by "Items".


I think the required changes would be something like:

==========
MyControl
==========

public class ControlItemCollection
{
...

public ControlItem Add(ControlItem controlItem)
{
return controlItem;
}
}

But I'm not really sure how to piece it all together, so the
'ControlItem' object is passed and added to the Master collection that
resides within the Control itself.

If anyone can help me out with this complexity.. my hats off to ya.

Nov 15 '05 #3

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

Similar topics

3
2376
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
0
1622
by: Shailaja Kulkarni | last post by:
Hi All, I am new to component development. I want to create custom control to arrange contained controls in form of polygonal shape. The objects are placed in separate panel on the some form....
12
5289
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
9
4671
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
0
3231
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
4
1486
by: cashdeskmac | last post by:
I have created a control and added a few properties. One of these is an array of DateTime objects, looking like this: public DateTime MyDates { get { return theDate;} set {theDate =...
1
1910
by: Suresh | last post by:
Using ASP.NET 1.1 ---------------------- I have a custom collection of object that I'm binding to a datagrid. Each of these objects have another collection inside them. I have a user control...
2
4206
by: R.A.F. | last post by:
Hi, I have a custom control in which i have a collection property named "Columns". this collection property add/remove column objects. in my Column class i have a property named Alignment...
3
1919
by: =?Utf-8?B?R2hpc3Rvcw==?= | last post by:
Hi all, We have a N-Tier framework and we now create a Web Site App to wotk with this architecture. I add reference from my libraries in the project and creating page and controls is very...
0
7134
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,...
0
7012
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
7180
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,...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5479
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,...
0
3105
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...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
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...

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.