Gets or sets the report fields that are currently selected in the editor.

Namespace:  C1.Win.C1ReportDesigner
Assembly:  C1.Win.C1ReportDesigner.2 (in C1.Win.C1ReportDesigner.2.dll)

Syntax

C#
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
[BrowsableAttribute(false)]
public Field[] SelectedFields { get; set; }
Visual Basic
<DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)> _
<BrowsableAttribute(False)> _
Public Property SelectedFields As Field()
	Get
	Set

Remarks

This property exposes the selected fields, usually for editing with a PropertyGrid control.

This is one of the most important properties in the designer control. The designer control exposes a design pane that allows users to select, move, resize, copy, and delete fields. It also manages user selections, which are exposed through the SelectedFields and SelectedSection properties.

The control does not provide any means for editing most field and section properties (e.g. BackColor, ForeColor, Visible, etc). For this, the application should use a PropertyGrid control connected to the current selection, and it should update the property grid in response to events that indicate the selection has changed.

When several fields are selected, the last one in the selection is highlighted in a different color and is referred to as the reference field. When multiple fields are to be aligned or resized, the reference field provides the position and size to be used for the others. The second example below illustrates this.

Examples

The code below shows how the C1ReportDesigner application manages the connection between the PropertyGrid and the objects selected in the designer. The connection is made through the designer's SelectionChanged event.

Depending on the selection, the grid shows the properties of the selected fields, the selected section, or the whole report.

Copy CodeC#
// selection changed, update property grid
private void _designer_SelectionChanged(object sender, EventArgs e)
{
    // show field properties
    object[] sel = _designer.SelectedFields;
    if (sel.Length > 0)
    {
        _propLabel.Text = " Field Properties";
        _propGrid.SelectedObjects = sel;
    }
    // show section properties
    else if (_designer.SelectedSection != null) 
    {
        _propLabel.Text = " Section Properties";
        _propGrid.SelectedObject = _designer.SelectedSection;
    }
    // show report properties
    else if (_designer.Report != null) 
    {
        _propLabel.Text = " Report Properties";
        _propGrid.SelectedObject = _designer.Report;
    }
    // nothing to show...
    else 
    {
        _propLabel.Text = " Properties";
        _propGrid.SelectedObject = null;
    }

    // update UI (_menus, toolbars, etc)
    _designer.CreateFieldInfo = null;
    UpdateUI();
}
The SelectedFields property is also useful for implementing commands that act on a field or group of fields. For example, the C1ReportDesigner application has commands that allow the user to align the selected fields. The code below shows how you might implement some of these commands (note that the last field in the selection is used as a reference for aligning the others):
Copy CodeC#
// format toolbar 
private void _tbFormat_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
  // get ready to work
  Field[] sel = _designer.SelectedFields;
  Debug.Assert(sel.Length > 0);

  // get reference field (last in the selection)
  Field refFld = (Field)sel[sel.Length-1];

  // save undo info
  _designer.UndoStack.SaveState();

  // align fields
  if (e.Button == _btnAlignLeft)
  {
      for (int i = 0; i < sel.Length; i++)
          sel[i].Left = refFld.Left;
  } 
  else if (e.Button == _btnAlignCenter)
  {
      double mid = refFld.Left + refFld.Width/2;
      for (int i = 0; i < sel.Length; i++)
          sel[i].Left = mid - sel[i].Width/2;
  }
  else if (e.Button == _btnAlignRight)
  {
      double right = refFld.Left + refFld.Width;
      for (int i = 0; i < sel.Length; i++)
          sel[i].Left = right - sel[i].Width;
  }
  else if (e.Button == _btnAlignTop)
  {
      for (int i = 0; i < sel.Length; i++)
          sel[i].Top = refFld.Top;
  }
  else if (e.Button == _btnAlignMiddle)
  {
      double mid = refFld.Top + refFld.Height/2;
      for (int i = 0; i < sel.Length; i++)
          sel[i].Top = mid - sel[i].Height/2;
  }
  else if (e.Button == _btnAlignBottom)
  {
      double bottom = refFld.Top + refFld.Height;
      for (int i = 0; i < sel.Length; i++)
          sel[i].Top = bottom - sel[i].Height;
  }

  // show the changes
  _designer.Refresh();
  UpdateUI();
}

See Also