Ejemplo n.º 1
0
        private void DecreaseIndentationButton_Click(object sender, RoutedEventArgs e)
        {
            List <GanttChartItem> items = new List <GanttChartItem>();

            foreach (GanttChartItem item in GanttChartDataGrid.GetSelectedItems())
            {
                items.Add(item);
            }
            if (items.Count <= 0)
            {
                MessageBox.Show("Cannot decrease indentation for the selected item(s) as the selection is empty; select an item first.", "Information", MessageBoxButton.OK);
                return;
            }
            items.Reverse();
            foreach (GanttChartItem item in items)
            {
                if (item.Indentation > 0)
                {
                    int            index    = GanttChartDataGrid.IndexOf(item);
                    GanttChartItem nextItem = index < GanttChartDataGrid.Items.Count - 1 ? GanttChartDataGrid[index + 1] : null;
                    if (nextItem == null || item.Indentation >= nextItem.Indentation)
                    {
                        item.Indentation--;
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Cannot increase indentation for {0} because the next item is one of its child items; decrease the indentation of its child items first.", item), "Information", MessageBoxButton.OK);
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("Cannot decrease indentation for {0} because it is on the first indentation level, being a root item.", item), "Information", MessageBoxButton.OK);
                }
            }
        }
Ejemplo n.º 2
0
        private void IncreaseIndentationButton_Click(object sender, RoutedEventArgs e)
        {
            List <GanttChartItem> items = new List <GanttChartItem>();

            foreach (GanttChartItem item in GanttChartDataGrid.GetSelectedItems())
            {
                items.Add(item);
            }
            if (items.Count <= 0)
            {
                MessageBox.Show("Cannot increase indentation for the selected item(s) as the selection is empty; select an item first.", "Information", MessageBoxButton.OK);
                return;
            }
            foreach (GanttChartItem item in items)
            {
                int index = GanttChartDataGrid.IndexOf(item);
                if (index > 0)
                {
                    GanttChartItem previousItem = GanttChartDataGrid[index - 1];
                    if (item.Indentation <= previousItem.Indentation)
                    {
                        item.Indentation++;
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Cannot increase indentation for {0} because the previous item is its parent item; increase the indentation of its parent item first.", item), "Information", MessageBoxButton.OK);
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("Cannot increase indentation for {0} because it is the first item; insert an item before this one first.", item), "Information", MessageBoxButton.OK);
                }
            }
        }