/// <summary> /// Moves the selected elements down in the order of columns. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="e">The event arguments.</param> private void buttonMoveDown_Click(object sender, System.EventArgs e) { // This will suspend the events while the lists are udpated. this.listBoxDisplayedFields.BeginUpdate(); // This willl move each of the items in a downward direction in the list of displayed columns. int[] selectedIndices = new int[this.listBoxDisplayedFields.SelectedIndices.Count]; this.listBoxDisplayedFields.SelectedIndices.CopyTo(selectedIndices, 0); Array.Reverse(selectedIndices); foreach (int selectedIndex in selectedIndices) { // This will stop the operation when the selected columns have reached the rightmost side of the document. if (selectedIndex == this.listBoxDisplayedFields.Items.Count - 1) { break; } // Move the element down in the ordering of the column list data structure. Stylesheet.ColumnNode sourceColumn = (Stylesheet.ColumnNode) this.listBoxDisplayedFields.Items[selectedIndex]; Stylesheet.ColumnNode destinationColumn = (Stylesheet.ColumnNode) this.listBoxDisplayedFields.Items[selectedIndex + 1]; int sourceIndex = this.columnList.IndexOf(sourceColumn); int destinationIndex = this.columnList.IndexOf(destinationColumn); this.columnList.Move(sourceIndex, destinationIndex); // Move the element down the list box also. this.listBoxDisplayedFields.Items.RemoveAt(selectedIndex); this.listBoxDisplayedFields.Items.Insert(selectedIndex + 1, sourceColumn); this.listBoxDisplayedFields.SetSelected(selectedIndex + 1, true); } // This will re-enable the events this.listBoxDisplayedFields.EndUpdate(); }
/// <summary> /// Moves the selected elements up in the order of columns. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="e">The event arguments.</param> private void buttonMoveUp_Click(object sender, System.EventArgs e) { // This will suspend the events while the lists are udpated. this.listBoxDisplayedFields.BeginUpdate(); // This will move the selected items upward in the list box. foreach (int selectedIndex in this.listBoxDisplayedFields.SelectedIndices) { // Halt the operation if the columns are already at the start of the report. With a multiple selection, this will // appear to halt the whole train of selected items when it reaches the start of the column list. if (selectedIndex == 0) { break; } // Move the element up one in the ordering of the columns in the internal data structures. Stylesheet.ColumnNode sourceColumn = (Stylesheet.ColumnNode) this.listBoxDisplayedFields.Items[selectedIndex]; Stylesheet.ColumnNode destinationColumn = (Stylesheet.ColumnNode) this.listBoxDisplayedFields.Items[selectedIndex - 1]; int sourceIndex = this.columnList.IndexOf(sourceColumn); int destinationIndex = this.columnList.IndexOf(destinationColumn); this.columnList.Move(sourceIndex, destinationIndex); // Move the element up in the list box also. this.listBoxDisplayedFields.Items.RemoveAt(selectedIndex); this.listBoxDisplayedFields.Items.Insert(selectedIndex - 1, sourceColumn); this.listBoxDisplayedFields.SetSelected(selectedIndex - 1, true); } // This will re-enable the events this.listBoxDisplayedFields.EndUpdate(); }
/// <summary> /// Parses the XSL Stylesheet for the description of a column. /// </summary> /// <param name="xmlTokenReader">Represents a reader that provides fast, non-cached, forward only access to XML Data.</param> public void ParseColumnStart() { // Create a Column Node and initialize from the incoming XSL data. Stylesheet.ColumnNode column = new Stylesheet.ColumnNode(); // Add this node to current parent node and then push it onto the stack. These elements will form a tree structure // roughly equivalent to the same form they had in the XML file. this.nodeStack.Peek().Add(column); this.nodeStack.Push(column); }
/// <summary> /// Removes a column from the list of displayed columns. /// </summary> /// <param name="sender">The object that originated the event.</param> /// <param name="e">The event arguments.</param> private void buttonRemove_Click(object sender, System.EventArgs e) { // Make each of the selected columns visible and move it from the 'Displayed' list to the 'Displayed list. Note that // the selection is changed during the loop, so a copy of the selected items is needed for the loop. Stylesheet.ColumnNode[] selectedItems = new Stylesheet.ColumnNode[this.listBoxDisplayedFields.SelectedItems.Count]; this.listBoxDisplayedFields.SelectedItems.CopyTo(selectedItems, 0); // HACK - make this work with the new ColumnView //foreach (Stylesheet.ColumnNode column in selectedItems) // column.IsDisplayed = false; DrawListBoxes(); }
/// <summary>Populate the list boxes with the hidden and displayed columns available.</summary> private void DrawListBoxes() { // Populate the 'Available' list of columns with the hidden columns. Note that a 'ColumnItem' class is needed to get a // readable name for the items displayed in the list box. // HACK - This needs to work with the ViewColumns list. Stylesheet.ColumnsNode availableList = new Stylesheet.ColumnsNode(); Stylesheet.ColumnsNode displayedList = new Stylesheet.ColumnsNode(); //foreach (Stylesheet.ColumnNode column in this.columnList) // (column.IsDisplayed ? displayedList : availableList).Add(column); Stylesheet.ColumnNode[] availableColumns = new Stylesheet.ColumnNode[availableList.Count]; availableList.CopyTo(availableColumns, 0); Stylesheet.ColumnNode[] displayedColumns = new Stylesheet.ColumnNode[displayedList.Count]; displayedList.CopyTo(displayedColumns, 0); // This will preserve the selection of the available (hidden) columns when the list is redrawn. ListBox.SelectedObjectCollection selectedAvailableObjects = this.listBoxAvailableFields.SelectedItems; Stylesheet.ColumnNode[] selectedAvailableColumns = new Stylesheet.ColumnNode[selectedAvailableObjects.Count]; selectedAvailableObjects.CopyTo(selectedAvailableColumns, 0); // This will preserve the selection of the displayed (visible) columns when the list is redrawn. ListBox.SelectedObjectCollection selectedDisplayedObjects = this.listBoxDisplayedFields.SelectedItems; Stylesheet.ColumnNode[] selectedDisplayedColumns = new Stylesheet.ColumnNode[selectedDisplayedObjects.Count]; selectedDisplayedObjects.CopyTo(selectedDisplayedColumns, 0); // Clear out the previous entries and repopulate the list of available (hidden) fields. Note that the updating is // suspended so the user doesn't see the items cleared out. If the updating were not inhibited, there would be a // noticable 'blink' as the items were cleared and repopulated. Note that the selected state of the items is preserved when the list is // redrawn. this.listBoxAvailableFields.BeginUpdate(); this.listBoxAvailableFields.Items.Clear(); this.listBoxAvailableFields.Items.AddRange(availableColumns); foreach (Stylesheet.ColumnNode column in selectedAvailableColumns) { int index = this.listBoxAvailableFields.Items.IndexOf(column); if (index != -1) { this.listBoxAvailableFields.SetSelected(index, true); } } foreach (Stylesheet.ColumnNode column in selectedDisplayedColumns) { int index = this.listBoxAvailableFields.Items.IndexOf(column); if (index != -1) { this.listBoxAvailableFields.SetSelected(index, true); } } this.listBoxAvailableFields.EndUpdate(); // Do the same for the displayed fields. Note that the selected state of the items is preserved when the list is // redrawn. this.listBoxDisplayedFields.BeginUpdate(); this.listBoxDisplayedFields.Items.Clear(); this.listBoxDisplayedFields.Items.AddRange(displayedColumns); foreach (Stylesheet.ColumnNode column in selectedAvailableColumns) { int index = this.listBoxDisplayedFields.Items.IndexOf(column); if (index != -1) { this.listBoxDisplayedFields.SetSelected(index, true); } } foreach (Stylesheet.ColumnNode column in selectedDisplayedColumns) { int index = this.listBoxDisplayedFields.Items.IndexOf(column); if (index != -1) { this.listBoxDisplayedFields.SetSelected(index, true); } } this.listBoxDisplayedFields.EndUpdate(); }