Beispiel #1
0
        /// <summary>
        /// Adds the specified number of rows to the bottom of the table.
        /// </summary>
        /// <param name="count">The number of rows to add to the bottom of the table.</param>
        /// <param name="headerTexts">Optional strings to apply to the header labels of the new rows.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="count"/> is less than 0.</exception>
        public void AddRows(int count, params string[] headerTexts)
        {
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "Value cannot be less than 0.");
            }

            var list         = RowHeaders.ToList();
            int currentCount = list.Count;

            for (int i = 0; i < count; i++)
            {
                var label = new Label();
                label.Text = headerTexts != null && headerTexts.Length > i ? headerTexts[i] : null;
                label.HorizontalAlignment = HorizontalAlignment.Left;
                label.VerticalAlignment   = VerticalAlignment.Center;

                NativeCell.AddChild(label);
                list.Add(label);
            }

            RowHeaders = new ReadOnlyCollection <Label>(list);

            for (int i = 0; i < columnControls.Length; i++)
            {
                var cc = columnControls[i];
                Array.Resize(ref cc, RowCount);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Removes the specified number of rows from the bottom of the table.
        /// </summary>
        /// <param name="count">The number of rows to remove from the bottom of the table.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="count"/> is less than 0 -or-
        /// when <paramref name="count"/> is greater than the number of rows currently in the table.</exception>
        public void RemoveRows(int count)
        {
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "Value cannot be less than 0.");
            }

            if (count > RowCount)
            {
                throw new ArgumentOutOfRangeException("count", "Value cannot be greater than the number of rows currently in the table.");
            }

            var list = RowHeaders.ToList();

            for (int i = list.Count - 1; i >= list.Count - count; i--)
            {
                NativeCell.RemoveChild(list[i]);
                list.RemoveAt(i);

                foreach (var cc in columnControls)
                {
                    NativeCell.RemoveChild(cc[i]);
                }
            }

            for (int i = 0; i < columnControls.Length; i++)
            {
                Array.Resize(ref columnControls[i], RowCount - count);
            }

            RowHeaders = new ReadOnlyCollection <Label>(list);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var random = new Random();
            var row    = random.Next(50, 100);
            var col    = random.Next(50, 100);

            RowHeaders.Clear();
            Enumerable.Range(0, row).ToList()
            .ForEach(r => RowHeaders.Add($"R{r}"));

            ColumnHeaders.Clear();
            Enumerable.Range(0, col).ToList()
            .ForEach(c => ColumnHeaders.Add($"C{c}"));

            Items.Clear();
            RowHeaders.ToList()
            .ForEach(r => Items.Add(new ObservableCollection <string>(ColumnHeaders.Select(c => $"{c}-{r}"))));
        }