SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Custom control collection property problem

Last post 03-31-2009 3:03 PM by svem. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-27-2008 9:55 AM

    • svem
    • Not Ranked
    • Joined on 06-27-2008
    • Posts 2

    Custom control collection property problem

    I have problem with my custom control collection property on Compact Framework - no correct code generated in InitializeComponent(). As a result I can open CollectionEditor, can insert new items, can assign property values in design-time, but this items and its properties don't saved when project reopened. I found some mistake in InitializeControl() autogenerated code - may be it's a result of my collection class realization errors.

    Please, help me.
    This is my code:

        //simple item class
        public class GridColumnItem
        {
            //fields, properties & etc...
        }
        // collection class
        public class GridColumns : System.Collections.CollectionBase
        {
            public GridColumns()
            {
            }
            public void Add(GridColumnItem item)
            {
                if (List.IndexOf(item) == -1)
                    List.Add(item);
            }
            public void AddRange(GridColumnItem[ items)
            {
                foreach (GridColumnItem clm in items)
                    List.Add(clm);
            }
            public int IndexOf(GridColumnItem item)
            {
                return List.IndexOf(item);
            }
            public void Insert(int index, GridColumnItem item)
            {
                List.Insert(index, item);
            }
            public void Remove(GridColumnItem item)
            {
                List.Remove(item);
            }
            public bool Contains(GridColumnItem item)
            {
                return List.Contains(item);
            }
            public ArrayList Items()
            {
                return this.InnerList;
            }
            public GridColumnItem this[int index]
            {
                get { return (GridColumnItem)List[index];}
                set { List[index] = value;}
            }
        }
        // collaction usage
        public partial class EnhGrid : DataGrid
        {
            private GridColumns columns = null;
            public GridColumns Columns
            {
                get {
                    if (columns == null)
                        columns = new GridColumns();
                    return columns;
                }
                set {
                    if (columns == null)
                        columns = new GridColumns();
                    columns.AddRange((GridColumnItem[)value.Items().ToArray(typeof(GridColumnItem)));
                }
            }

    All GridColumnItem items initilalization are generated in x.designer.cs module, but property EnhGrid.Columns does not initialized. New instance of GridColumns does not assigned to Columns property:
                
       new GridColumns().AddRange(new GridColumnItem[ {...}); //No any assignments...

    But I expected the next:

       Grid1.Columns.AddRange(new GridColumnItem[ {...});

    All works good if I corrent this line manualy, but after source modifications this line generated again....

    Will be very grateful for any help.
    Best regards, Sergey.

  • 03-30-2009 7:10 PM In reply to

    Re: Custom control collection property problem

     Sergey,

     Have you figured out a solution for your problem. I'm having the exact same issue and for the life of me can't figure it out.

     Thanks!

    Dylan

  • 03-31-2009 3:03 PM In reply to

    • svem
    • Not Ranked
    • Joined on 06-27-2008
    • Posts 2

    Re: Custom control collection property problem

    I found more simple solution for my task, than an attempt to resolve the problems with class serialization.
    I wrote a method to override items in the source collection. This method calls on FormLoad event:

    public partial class EnhGrid : DataGrid
    {
        ...
        public int InitColumns(...)
        {
            DataGridTableStyle grStyle; // item of the table style collection
            DataGridColumnStyle col; // item of the column style collection

            if ((this.Site != null) && (!this.Site.DesignMode) && (TableStyles.Count > 0))
            {
                grStyle = new DataGridTableStyle(); // create new table style item
                // copy properties values
                ...

                foreach (DataGridColumnStyle clm in TableStyles[0].GridColumnStyles)
                {
                    // create my own collection item dirived from DataGridTextBoxColumn
                    col = new ColumnStyle(...);

                   // init properties etc.
                   ...

                   grStyle.GridColumnStyles.Add(col);
                }

                // replace source collection property
                TableStyles.Clear();
                TableStyles.Add(grStyle);

                 ...
            }
        }
    ...

Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.