Exemplo n.º 1
0
            /// <summary>
            /// Inserts item to <see cref="DataGrid" />.
            /// </summary>
            /// <param name="index">The index.</param>
            /// <returns>
            /// Returns <c>true</c> if insertion is successful, <c>false</c> otherwise.
            /// </returns>
            public override bool InsertItem(int index)
            {
                var list = this.ItemsSource;

                if (list == null)
                {
                    return(false);
                }

                var itemType = TypeHelper.GetItemType(list);

                var newList = Owner.CreateInstance(itemType) as IList;

                var innerType = TypeHelper.GetInnerTypeOfList(list);

                if (innerType == null)
                {
                    return(false);
                }

                if (this.Owner.ItemsInRows)
                {
                    if (newList != null)
                    {
                        for (var ii = 0; ii < this.Owner.Columns; ii++)
                        {
                            newList.Add(Owner.CreateInstance(innerType));
                        }

                        if (index < 0)
                        {
                            list.Add(newList);
                        }
                        else
                        {
                            list.Insert(index, newList);
                        }
                    }
                }
                else
                {
                    // insert/append one new element to each list.
                    foreach (var row in list.OfType <IList>())
                    {
                        var newItem = Owner.CreateInstance(innerType);
                        if (index < 0)
                        {
                            row.Add(newItem);
                        }
                        else
                        {
                            row.Insert(index, newItem);
                        }
                    }
                }

                return(true);
            }
Exemplo n.º 2
0
        /// <summary>
        /// Generate column definitions based on a list of items.
        /// </summary>
        /// <param name="list">The list of items.</param>
        /// <returns>A sequence of column definitions.</returns>
        protected override IEnumerable <ColumnDefinition> GenerateColumnDefinitions(IList list)
        {
            var innerType = TypeHelper.GetInnerTypeOfList(list) ?? typeof(object);
            var firstRow  = list.Cast <IList>().FirstOrDefault();
            var columns   = firstRow?.Count ?? 0;

            for (var ii = 0; ii < columns; ii++)
            {
                yield return
                    (new ColumnDefinition
                {
                    Header = innerType.Name,
                    HorizontalAlignment = this.DefaultHorizontalAlignment,
                    Width = this.DefaultColumnWidth
                });
            }
        }
Exemplo n.º 3
0
            /// <summary>
            /// Generate column definitions based on <seealso cref="DataGridOperator.ItemsSource" />.
            /// </summary>
            /// <seealso cref="DataGridOperator.ItemsSource" />
            public override void GenerateColumnDefinitions()
            {
                var list      = this.ItemsSource;
                var innerType = TypeHelper.GetInnerTypeOfList(list);
                var firstRow  = list.Cast <IList>().FirstOrDefault();
                var columns   = firstRow != null ? firstRow.Count : 0;

                for (var ii = 0; ii < columns; ii++)
                {
                    Owner.ColumnDefinitions.Add(
                        new ColumnDefinition
                    {
                        PropertyType        = innerType ?? typeof(object),
                        Header              = innerType != null ? innerType.Name : string.Empty,
                        HorizontalAlignment = Owner.DefaultHorizontalAlignment,
                        Width = Owner.DefaultColumnWidth
                    });
                }
            }