User Control - Having the collections show up in property window

J

Jay Douglas

I need help getting the collections to show up in the property window of a
user control. I want to be able to edit the collection items just like any
other asp.net control that has collection properties (i.e. The ASP:Table
control). This is for a menu system. The collections are working when the
classes are called directly, but not as a user control. Any advice is
appreciated.

Code:
------

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;


namespace DropDownMenuControl
{
/// <summary>
/// Summary description for DropDownMenu.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:DropDownMenu runat=server></{0}:DropDownMenu>")]
public class DropDownMenu : System.Web.UI.WebControls.WebControl
{
private MenuList menuList = null;
private string text = string.Empty;

[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty),
NotifyParentProperty(true)
]
public MenuList Menu
{
get
{
if(menuList == null)
{
menuList = new MenuList();
}
return menuList;

}
}

[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}

}



public class MenuList
{

private MenuCategories categories = new MenuCategories();

public MenuList()
{
//
// TODO: Add constructor logic here
//
}

public MenuCategories MenuCategories
{
get
{
return categories;
}
set
{
categories = value;
}
}

public void AddCategory(MenuCategory menuCategory)
{
categories.AddCategory(menuCategory);
}

}


public class MenuCategories : IEnumerable
{

private ArrayList categories = new ArrayList();

public MenuCategories()
{
//
// TODO: Add constructor logic here
//
}

public int Count
{
get
{
return categories.Count;
}
}

public void AddCategory(MenuCategory category)
{
categories.Add(category);
}

public IEnumerator GetEnumerator()
{
return new MenuCategoriesEnumerator(categories);

}
}


public class MenuCategoriesEnumerator : IEnumerator
{

private ArrayList categories = new ArrayList();
private int position = -1;

public MenuCategoriesEnumerator(ArrayList categories)
{
this.categories = categories;
}

public object Current
{
get
{
return categories[position];

}
}

public bool MoveNext()
{
if (position < categories.Count - 1)
{
position ++;
return true;
}
else
{
return false;
}
}

public void Reset()
{
position = -1;
}

}


public class MenuCategory
{

private MenuCommands commands = new MenuCommands();
//private ArrayList categories = new ArrayList();

public MenuCategory()
{
//
// TODO: Add constructor logic here
//
}

public string HeaderText = string.Empty;
public string HeaderUrl = string.Empty;

public MenuCommands Commands
{
get
{
return commands;
}
set
{
commands = value;
}
}

public void AddCommand(MenuCommand menuCommand)
{
commands.AddCommand(menuCommand);
}

}

public class MenuCommands : IEnumerable
{

private ArrayList commands = new ArrayList();

public MenuCommands()
{
//
// TODO: Add constructor logic here
//
}

public int Count
{
get
{
return commands.Count;
}
}

public void AddCommand(MenuCommand menuCommand)
{
commands.Add(menuCommand);
}

public IEnumerator GetEnumerator()
{
return new MenuCommandsEnumerator(commands);

}
}


public class MenuCommandsEnumerator : IEnumerator
{

private ArrayList commands = new ArrayList();
private int position = -1;

public MenuCommandsEnumerator(ArrayList menuCommands)
{
commands = menuCommands;
}

public object Current
{
get
{
return commands[position];

}
}

public bool MoveNext()
{
if (position < commands.Count - 1)
{
position ++;
return true;
}
else
{
return false;
}
}

public void Reset()
{
position = -1;
}


}


public class MenuCommand
{

private string text = "";
private string url = "";

/// <summary>
/// Create a new menu command
/// </summary>
/// <param name="commandText">Text that is displayed in the menu
command</param>
/// <param name="commandUrl">The url that the menu command
launches</param>
public MenuCommand(string commandText, string commandUrl)
{
text = commandText;
url = commandUrl;
}

/// <summary>
/// Text that is displayed in the menu command
/// </summary>
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}

/// <summary>
/// The url that the menu command launches
/// </summary>
public string Url
{
get
{
return url;
}
set
{
url = value;
}
}


}

}
 
J

Jay Douglas

I was creating the collection all wrong. I finally found my solution at:
http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&th=b41749a52906a51a&rnum=3

--
Jay Douglas
Fort Collins, CO



Jay Douglas said:
I need help getting the collections to show up in the property window of a
user control. I want to be able to edit the collection items just like any
other asp.net control that has collection properties (i.e. The ASP:Table
control). This is for a menu system. The collections are working when the
classes are called directly, but not as a user control. Any advice is
appreciated.

Code:
------

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;


namespace DropDownMenuControl
{
/// <summary>
/// Summary description for DropDownMenu.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:DropDownMenu runat=server></{0}:DropDownMenu>")]
public class DropDownMenu : System.Web.UI.WebControls.WebControl
{
private MenuList menuList = null;
private string text = string.Empty;

[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty),
NotifyParentProperty(true)
]
public MenuList Menu
{
get
{
if(menuList == null)
{
menuList = new MenuList();
}
return menuList;

}
}

[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}

set
{
text = value;
}
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}

}



public class MenuList
{

private MenuCategories categories = new MenuCategories();

public MenuList()
{
//
// TODO: Add constructor logic here
//
}

public MenuCategories MenuCategories
{
get
{
return categories;
}
set
{
categories = value;
}
}

public void AddCategory(MenuCategory menuCategory)
{
categories.AddCategory(menuCategory);
}

}


public class MenuCategories : IEnumerable
{

private ArrayList categories = new ArrayList();

public MenuCategories()
{
//
// TODO: Add constructor logic here
//
}

public int Count
{
get
{
return categories.Count;
}
}

public void AddCategory(MenuCategory category)
{
categories.Add(category);
}

public IEnumerator GetEnumerator()
{
return new MenuCategoriesEnumerator(categories);

}
}


public class MenuCategoriesEnumerator : IEnumerator
{

private ArrayList categories = new ArrayList();
private int position = -1;

public MenuCategoriesEnumerator(ArrayList categories)
{
this.categories = categories;
}

public object Current
{
get
{
return categories[position];

}
}

public bool MoveNext()
{
if (position < categories.Count - 1)
{
position ++;
return true;
}
else
{
return false;
}
}

public void Reset()
{
position = -1;
}

}


public class MenuCategory
{

private MenuCommands commands = new MenuCommands();
//private ArrayList categories = new ArrayList();

public MenuCategory()
{
//
// TODO: Add constructor logic here
//
}

public string HeaderText = string.Empty;
public string HeaderUrl = string.Empty;

public MenuCommands Commands
{
get
{
return commands;
}
set
{
commands = value;
}
}

public void AddCommand(MenuCommand menuCommand)
{
commands.AddCommand(menuCommand);
}

}

public class MenuCommands : IEnumerable
{

private ArrayList commands = new ArrayList();

public MenuCommands()
{
//
// TODO: Add constructor logic here
//
}

public int Count
{
get
{
return commands.Count;
}
}

public void AddCommand(MenuCommand menuCommand)
{
commands.Add(menuCommand);
}

public IEnumerator GetEnumerator()
{
return new MenuCommandsEnumerator(commands);

}
}


public class MenuCommandsEnumerator : IEnumerator
{

private ArrayList commands = new ArrayList();
private int position = -1;

public MenuCommandsEnumerator(ArrayList menuCommands)
{
commands = menuCommands;
}

public object Current
{
get
{
return commands[position];

}
}

public bool MoveNext()
{
if (position < commands.Count - 1)
{
position ++;
return true;
}
else
{
return false;
}
}

public void Reset()
{
position = -1;
}


}


public class MenuCommand
{

private string text = "";
private string url = "";

/// <summary>
/// Create a new menu command
/// </summary>
/// <param name="commandText">Text that is displayed in the menu
command</param>
/// <param name="commandUrl">The url that the menu command
launches</param>
public MenuCommand(string commandText, string commandUrl)
{
text = commandText;
url = commandUrl;
}

/// <summary>
/// Text that is displayed in the menu command
/// </summary>
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}

/// <summary>
/// The url that the menu command launches
/// </summary>
public string Url
{
get
{
return url;
}
set
{
url = 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