Create a new OutlookGridGroup

You may want to group your data in another way that the ones provided by the grid.
Please take a look to the following steps :

1. Create a new class
2. Overrides the text property. Used for the text associated to the group and displayed to the user
3. Overrides the Group value. Use to put rows in the group and to sort groups between them.
4. Overrides the Clone() method.
5 Overrides the CompareTo() method.

    public class OutlookGridExampleGroup : OutlookgGridDefaultGroup
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parentGroup">The parentGroup if any.</param>
        public OutlookGridExampleGroup(IOutlookGridGroup parentGroup)
            : base(parentGroup)
        {
        }

        /// <summary>
        /// Gets or sets the displayed text.
        /// </summary>
        public override string Text
        {
            get
            {
                return string.Format("{0}: {1} ({2})", column.DataGridViewColumn.HeaderText, Value.ToString(), itemCount == 1 ? LangManager.Instance.GetString("OneItem") : itemCount.ToString() + LangManager.Instance.GetString("XXXItems"));

            }
            set
            {
                text = value;
            }
        }

        /// <summary>
        /// Gets or sets the value
        /// </summary>
        public override object Value
        {
            get
            {
                return val;
            }
            set
            {
                val = value.ToString();
            }
        }

        #region ICloneable Members

        /// <summary>
        /// Overrides the Clone() function
        /// </summary>
        /// <returns>OutlookGridExampleGroup</returns>
        public override object Clone()
        {
            OutlookGridExampleGroupgr = new OutlookGridExampleGroup(this.parentGroup);
            gr.column = this.column;
            gr.val = this.val;
            gr.collapsed = this.collapsed;
            gr.text = this.text;
            gr.height = this.height;
            return gr;
        }

        #endregion

        #region IComparable Members
        /// <summary>
        /// Overrides the CompareTo
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override int CompareTo(object obj)
        {
            int orderModifier = (Column.SortDirection == SortOrder.Ascending ? 1 : -1);

            if (obj is OutlookGridExampleGroup)
            {
               return string.Compare(val.ToString(), ((OutlookGridExampleGroup)obj).Value.ToString()) * orderModifier;
            }
            else
            {
                return 0;
            }
        }
        #endregion IComparable Members
    }

Last edited May 25, 2013 at 11:10 PM by Cocotteseb, version 2