473,799 Members | 2,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

item and subitem collections

I trying to do nested items in a collection.

I've got an item which one of the properties is subitems, which is a
collection of item. can do the root level but if i do a subitem at design
time i get an object not set error. it's like a menuitem or treenode which
can have subitems of the same type. cant find any help on nested items.

is there anyone out there that help?

Many thanks,

ash.
Nov 15 '05 #1
2 5643
ITEM CLASS:
using System;
using System.Componen tModel;
using System.Windows. Forms;

namespace AssistApplicati ons.Windows.For ms
{
[DesignTimeVisib le(false)]
public class CategoryItem : System.Componen tModel.Componen t
{
private string fTitle;
private CategoryItemCol lection fSubItems;
private string fValue;

public CategoryItem()
{
fSubItems = new CategoryItemCol lection();
}

public string Title
{
get { return fTitle; }
set { fTitle = value; }
}
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public CategoryItemCol lection SubItems
{
get { return fSubItems; }
}
public string Value
{
get { return fValue; }
set { fValue = value; }
}

}
}
ITEM COLLECTION:
using System;
using System.Collecti ons;
using System.Windows. Forms;

namespace AssistApplicati ons.Windows.For ms
{
public class CategoryItemCol lection : System.Collecti ons.CollectionB ase
{
public delegate void CollectionChang e(int index, object value);
private event CollectionChang e fInserting;
private event CollectionChang e fInsertComplete ;

protected override void OnInsert(int index, object value)
{
CategoryItem item = value as CategoryItem;
if(item.Title == null)
item.Title = String.Concat(" Item", Count.ToString( ));
base.OnInsert(i ndex, item);
if(fInserting != null)
{
fInserting(inde x, value);
}
}
protected override void OnInsertComplet e(int index, object value)
{
base.OnInsertCo mplete (index, value);
if(fInsertCompl ete != null)
{
fInsertComplete (index, value);
}
}
public CategoryItemCol lection(){}
public int Add(CategoryIte m item)
{
if(Contains(ite m)) return -1;
int index = List.Add(item);
//OnAddPanel(new PanelEventArgs( panel));
return index;
}
public void AddRange(Catego ryItem[] items)
{
foreach(Categor yItem item in items)
Add(item);
}
public void Remove(int index)
{
if((index >= Count) || (index < 0))
return;
List.RemoveAt(i ndex);
}
public CategoryItem this[int index]
{
get
{
if(index < 0 || index >= Count)
return null;
return (CategoryItem)L ist[index];
}
}
public void Insert(int index, CategoryItem item)
{
List.Insert(ind ex, item);
}
public int IndexOf(Categor yItem item)
{
return List.IndexOf(it em);
}
public bool Contains(Catego ryItem item)
{
return InnerList.Conta ins(item);
}
public event CollectionChang e Inserting
{
add { fInserting += value; }
remove { fInserting -= value; }
}
public event CollectionChang e InsertComplete
{
add { fInsertComplete += value; }
remove { fInsertComplete -= value; }
}

}
}
Control class:
refences the items as in item but with the name as Items e.g.

[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public CategoryItemCol lection Items
{
get { return fItems; }
}

What I'm trying to do is like treenode and menitems they can subitems of the
same type but trying to do this at design time.
if i load it at runtime it works fine. I have no idea on how to do this and
there is no help out there.

Thanks,

ash.

"codewriter " <co************ **@yahoo.com> wrote in message
news:pG******** ***********@new s20.bellglobal. com...
Post your code.

"Ash Jones" <as*@ashtek.me. uk> wrote in message
news:OR******** *****@tk2msftng p13.phx.gbl...
I trying to do nested items in a collection.

I've got an item which one of the properties is subitems, which is a
collection of item. can do the root level but if i do a subitem at design time i get an object not set error. it's like a menuitem or treenode which can have subitems of the same type. cant find any help on nested items.

is there anyone out there that help?

Many thanks,

ash.


Nov 15 '05 #2
I tried this and it worked fine:
private void button1_Click(o bject sender, System.EventArg s e)

{

CategoryItemCol lection oCol = new CategoryItemCol lection();

for(int i = 0; i<10; i++)

{

CategoryItem oItem = new CategoryItem();

oItem.Title = "Item" + i.ToString();

for(int j=0; j<10; j++)

{

CategoryItem oSubItem = new CategoryItem();

oSubItem.Title = "Subitem" + j.ToString();

oItem.SubItems. Add(oSubItem);

}

oCol.Add(oItem) ;

}

this.lstResourc es.Clear();

ColumnHeader oHeader = new ColumnHeader();

oHeader.Text = "Name";

oHeader.Width = lstResources.Wi dth;

this.lstResourc es.Columns.Add( oHeader);

foreach(Categor yItem oColItem in oCol)

{

ListViewItem oItem;

oItem = new ListViewItem(ne w string[] {oColItem.Title }

, -1, Color.Empty, Color.White, null);

this.lstResourc es.Items.Add(oI tem);

foreach(Categor yItem oColItem1 in oColItem.SubIte ms)

{

ListViewItem oItem1;

oItem1 = new ListViewItem(ne w string[] {oColItem1.Titl e}

, -1, Color.Empty, Color.White, null);

this.lstResourc es.Items.Add(oI tem1);

}

}

}

"Ash Jones" <as*@ashtek.me. uk> wrote in message
news:u4******** ******@TK2MSFTN GP12.phx.gbl...
ITEM CLASS:
using System;
using System.Componen tModel;
using System.Windows. Forms;

namespace AssistApplicati ons.Windows.For ms
{
[DesignTimeVisib le(false)]
public class CategoryItem : System.Componen tModel.Componen t
{
private string fTitle;
private CategoryItemCol lection fSubItems;
private string fValue;

public CategoryItem()
{
fSubItems = new CategoryItemCol lection();
}

public string Title
{
get { return fTitle; }
set { fTitle = value; }
}
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)] public CategoryItemCol lection SubItems
{
get { return fSubItems; }
}
public string Value
{
get { return fValue; }
set { fValue = value; }
}

}
}
ITEM COLLECTION:
using System;
using System.Collecti ons;
using System.Windows. Forms;

namespace AssistApplicati ons.Windows.For ms
{
public class CategoryItemCol lection : System.Collecti ons.CollectionB ase
{
public delegate void CollectionChang e(int index, object value);
private event CollectionChang e fInserting;
private event CollectionChang e fInsertComplete ;

protected override void OnInsert(int index, object value)
{
CategoryItem item = value as CategoryItem;
if(item.Title == null)
item.Title = String.Concat(" Item", Count.ToString( ));
base.OnInsert(i ndex, item);
if(fInserting != null)
{
fInserting(inde x, value);
}
}
protected override void OnInsertComplet e(int index, object value)
{
base.OnInsertCo mplete (index, value);
if(fInsertCompl ete != null)
{
fInsertComplete (index, value);
}
}
public CategoryItemCol lection(){}
public int Add(CategoryIte m item)
{
if(Contains(ite m)) return -1;
int index = List.Add(item);
//OnAddPanel(new PanelEventArgs( panel));
return index;
}
public void AddRange(Catego ryItem[] items)
{
foreach(Categor yItem item in items)
Add(item);
}
public void Remove(int index)
{
if((index >= Count) || (index < 0))
return;
List.RemoveAt(i ndex);
}
public CategoryItem this[int index]
{
get
{
if(index < 0 || index >= Count)
return null;
return (CategoryItem)L ist[index];
}
}
public void Insert(int index, CategoryItem item)
{
List.Insert(ind ex, item);
}
public int IndexOf(Categor yItem item)
{
return List.IndexOf(it em);
}
public bool Contains(Catego ryItem item)
{
return InnerList.Conta ins(item);
}
public event CollectionChang e Inserting
{
add { fInserting += value; }
remove { fInserting -= value; }
}
public event CollectionChang e InsertComplete
{
add { fInsertComplete += value; }
remove { fInsertComplete -= value; }
}

}
}
Control class:
refences the items as in item but with the name as Items e.g.

[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public CategoryItemCol lection Items
{
get { return fItems; }
}

What I'm trying to do is like treenode and menitems they can subitems of the same type but trying to do this at design time.
if i load it at runtime it works fine. I have no idea on how to do this and there is no help out there.

Thanks,

ash.

"codewriter " <co************ **@yahoo.com> wrote in message
news:pG******** ***********@new s20.bellglobal. com...
Post your code.

"Ash Jones" <as*@ashtek.me. uk> wrote in message
news:OR******** *****@tk2msftng p13.phx.gbl...
I trying to do nested items in a collection.

I've got an item which one of the properties is subitems, which is a
collection of item. can do the root level but if i do a subitem at design time i get an object not set error. it's like a menuitem or treenode which can have subitems of the same type. cant find any help on nested items.
is there anyone out there that help?

Many thanks,

ash.



Nov 15 '05 #3

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

Similar topics

2
3120
by: Angel Monson | last post by:
Is there a way I can find out which item I double-clicked inside a listview? And what about with subitems? And once I get an item number, can I use it to read the item and subitem contents? And if I click on one item, what do I need to do in order for me to highlight that item I clicked in the following X items? Since I'll be displaying addressses in the listbox, I'd like to be able to highlight the whole address when the user clicks on...
13
3773
by: Maheshkumar.R | last post by:
hi groups, I have placed an listview control, i want to iterate thru the control and find the clicked event items. listView2.Items.Add(fname.ToString(), i); how i can perform the iteration to find the item clicked...? and its item. thankz-- Mähésh Kumär. R
7
1893
by: Marc Bishop | last post by:
Hi can anyone help? I'm making a shopping cart and am stuck on removing an item from my array? The array is made : cArray(ITEM_NAME,cItem) = ProductName
3
15723
by: larry mckay | last post by:
anyone have the code to select and listview item or row (subitems) after a doubleclick event from a listview. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
0
2290
by: Smokey Grindle | last post by:
This is just a wierd one... I am trying to draw the sub items in the drawitem event of the list view in owner drawn mode (because of documented W32 rendering bugs) instead of in two seperate items drawitem and drawsubitems... but when I run this code in the drawitems For Each subItm As ListViewItem.ListViewSubItem In _tn.SubItems ' If subItm..ColumnIndex <0 Then 'If (e.State And Windows.Forms.ListViewItemStates.Selected) = 1 Then
1
5254
by: plmanikandan | last post by:
Hi, I have a listview with items,subitems.I tems and subitems are added as below listView1.View = View.Details; listView1.Columns.Add("Column 1", 100,HorizontalAlignment.Center); listView1.Columns.Add("Column 2", 100,HorizontalAlignment.Center); listView1.Columns.Add("Column 3", 100,HorizontalAlignment.Center); listView1.Columns.Add("Column 4", 100,HorizontalAlignment.Center); System.Windows.Forms.ListViewItem itmp = new
3
11637
by: sstein | last post by:
Hi, I am having a bit of trouble with some C# code. I can get it working in VB.NET, but can't seem to work out how to get the same code working in C#. I have a listview which stores information about employees. Basically Day, Hours Worked, Hours Off, Absence Reason, Subs, Pay for day.
7
3583
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR Me.cboLocation.Text = ""
3
25029
by: luiggye | last post by:
Hi I have a LISTVIEW where every item have 6 subitems (columns). lstBrowse.Columns.Add("Col1", 150, HorizontalAlignment.Left) lstBrowse.Columns.Add("Col2", 150, HorizontalAlignment.Left) lstBrowse.Columns.Add("Col3", 150, HorizontalAlignment.Left) lstBrowse.Columns.Add("Col4", 150, HorizontalAlignment.Left) lstBrowse.Columns.Add("Col5", 150, HorizontalAlignment.Left) lstBrowse.Columns.Add("Col6", 150, HorizontalAlignment.Left)
0
9687
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
10482
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
10251
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...
0
9072
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...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
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
2938
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.