User Control - Having the collections show up in property window

Discussion in 'ASP .Net Web Controls' started by Jay Douglas, Nov 2, 2003.

  1. Jay Douglas

    Jay Douglas Guest

    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;
    }
    }


    }

    }


    --
    Jay Douglas
    Fort Collins, CO
     
    Jay Douglas, Nov 2, 2003
    #1
    1. Advertising

  2. Jay Douglas

    Jay Douglas Guest

    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" <> wrote in message
    news:...
    > 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;
    > }
    > }
    >
    >
    > }
    >
    > }
    >
    >
    > --
    > Jay Douglas
    > Fort Collins, CO
    >
    >
    >
    >
     
    Jay Douglas, Nov 2, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Douglas
    Replies:
    1
    Views:
    2,261
    Jay Douglas
    Nov 2, 2003
  2. Matt
    Replies:
    2
    Views:
    14,185
    bruce barker
    Aug 23, 2004
  3. Doug Poland
    Replies:
    9
    Views:
    763
    VisionSet
    Sep 27, 2003
  4. Matt
    Replies:
    1
    Views:
    478
    Andrew Thompson
    Aug 22, 2004
  5. mutex
    Replies:
    0
    Views:
    230
    mutex
    Jul 27, 2003
Loading...

Share This Page