Esempio n. 1
0
        /// <summary>
        /// Reander list items to list box control.
        /// </summary>
        /// <param name="component">List box control.</param>
        /// <param name="itemsToRender">Specified list box items.</param>
        /// <param name="setHeight">A value indicating whether calculates control's height by item's position.</param>
        private void RenderItems(Control component, TemplateItemCollection itemsToRender, bool setHeight = true)
        {
            int itemCount  = itemsToRender.Count;
            int itemIndex  = 0;
            int rowIndex   = 0;
            int breakTimes = 0;

            component.Controls.Clear();

            while (itemIndex < itemCount)
            {
                int left  = ItemControlLeft;
                int top   = rowIndex * ItemControlTop;
                int index = 0;

                do
                {
                    Control control = GetTemplateItemControl(itemIndex, itemsToRender[itemIndex]);

                    if (left + control.PreferredSize.Width < Width || Column == 1)
                    {
                        component.Controls.Add(control);

                        control.Top  = top;
                        control.Left = left;

                        left += control.Width;

                        itemIndex++;
                        index++;
                    }
                    else
                    {
                        component.Controls.Remove(control);
                        breakTimes++;
                        break;
                    }
                } while (itemIndex < itemCount && (Column == 0 || index < Column));

                rowIndex++;

                if (breakTimes > itemCount)
                {
                    break;
                }
            }

            if (setHeight)
            {
                component.Height = component.Controls[itemCount - 1].Bottom;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Rerender list items when list box control's some property changed.
        /// </summary>
        private void RerenderItemsWhenPropertyChanged()
        {
            TemplateItemCollection items = null;

            //if there is no user data then show the default template items
            //else show the user data.
            if (!_isCustomized)
            {
                CreateDefaultTemplateItems();

                items = _tempItems;
            }
            else
            {
                items = Items;
            }

            RenderItems(Component, items);
        }