DekGenius.com
[ Team LiB ] Previous Section Next Section

DataGridmarshal by reference, disposable

System.Windows.Forms (system.windows.forms.dll)class

This class is the successor to the old unmanaged FlexGrid control, and has considerably more power, fully supporting complex data-binding scenarios.

A grid offers a two dimensional view of the rows and columns on a data source. The data source itself may consist of several related tables, each with different rows and columns, so the grid offers support for drilling down through these relations, updating the display to reflect the current view on the data.

There are a variety of basic areas in the grid whose appearance you can change. You can show and hide a caption (title) area with the CaptionVisible property. You can set the CaptionFont, CaptionForeColor, and CaptionBackColor, as well as the CaptionText.

If a particular row in the data source has been defined to have relations to another table, the grid displays a hyperlink for you to click on to follow that relation. You can set its LinkColor and LinkHoverColor. This drill-down behavior is enabled and disabled with the AllowNavigation property. When you have drilled down into a table, a line is added to display the parent rows through which you have navigated. You can set the ParentRowsBackColor, ParentRowsForeColor, and visibility (ParentRowsVisible). In addition, you can set the ParentRowsLabelStyle to display either the parent ColumnName, TableName, or both. You can also NavigateTo() a particular row and relation, or NavigateBack() to the parent of the current view.

Then, there are the column headers (which run across the top of the grid) and the row headers (which run down the side of the grid). You can make the ColumnHeadersVisible and the RowHeadersVisible, and also set the RowHeaderWidth. Their appearance can be modified with the HeaderBackColor, HeaderForeColor, and HeaderFont. (Note that this means the row and column headers must have the same basic appearance).

Finally, there are the data rows themselves. You can optionally display gridlines between the rows and/or columns by setting GridLineStyle and GridLineColor. You can set a PreferredRowHeight property that acts as a hint for the default row height, and find out the number of displayed rows using the VisibleRowCount property.

Rows can be selected, either with the mouse or programmatically through the Select() and UnSelect() methods (note the capital "S"), and you can set the SelectionForeColor and SelectionBackColor. The IsSelected() method determines the selection state of a particular row, and the CurrentRowIndex property tells you which row is currently selected. You can also set an AlternatingBackColor property to enable a ledger-like appearance for unselected rows.

The columns divide each row up into a series of cells. You can get the identity of the CurrentCell. Alternatively, you can get or set the value of a particular cell using the Item property (which is the indexer property). The display bounds of a particular cell can be retrieved using the GetCellBounds() method, or GetCurrentCellBounds() for the cell with the focus. You can choose whether the columns should be sorted by clicking on their headers by setting the AllowSorting property.

By default, the system automatically generates all the columns needed for each of the tables in the data source, generating textual, numeric, and Boolean columns as appropriate. However, you can also take control over the entire grid through the TableStyles property. This allows you to set up custom columns for each table. (See DataGridTableStyle and DataGridColumnStyle for more information on this feature of data grids.) Note that you must add your DataGridColumnStyle objects to your DataGridTableStyle objects before you add the table styles to the DataGrid, or the framework will handily create a default set of columns for you.

public class DataGrid : Control : System.ComponentModel.ISupportInitialize, IDataGridEditingService {
// Public Constructors
   public DataGrid();
// Public Instance Properties
   public bool AllowNavigation{set; get; }
   public bool AllowSorting{set; get; }
   public Color AlternatingBackColor{set; get; }
   public override Color BackColor{set; get; } // overrides Control
   public Color BackgroundColor{set; get; }
   public override Image BackgroundImage{set; get; } // overrides Control
   public BorderStyle BorderStyle{set; get; }
   public Color CaptionBackColor{set; get; }
   public Font CaptionFont{set; get; }
   public Color CaptionForeColor{set; get; }
   public string CaptionText{set; get; }
   public bool CaptionVisible{set; get; }
   public bool ColumnHeadersVisible{set; get; }
   public DataGridCell CurrentCell{set; get; }
   public int CurrentRowIndex{set; get; }
   public override Cursor Cursor{set; get; } // overrides Control
   public string DataMember{set; get; }
   public object DataSource{set; get; }
   public int FirstVisibleColumn{get; }
   public bool FlatMode{set; get; }
   public override Color ForeColor{set; get; } // overrides Control
   public Color GridLineColor{set; get; }
   public DataGridLineStyle GridLineStyle{set; get; }
   public Color HeaderBackColor{set; get; }
   public Font HeaderFont{set; get; }
   public Color HeaderForeColor{set; get; }
   public Color LinkColor{set; get; }
   public Color LinkHoverColor{set; get; }
   public Color ParentRowsBackColor{set; get; }
   public Color ParentRowsForeColor{set; get; }
   public DataGridParentRowsLabelStyle ParentRowsLabelStyle{set; get; }
   public bool ParentRowsVisible{set; get; }
   public int PreferredColumnWidth{set; get; }
   public int PreferredRowHeight{set; get; }
   public bool ReadOnly{set; get; }
   public bool RowHeadersVisible{set; get; }
   public int RowHeaderWidth{set; get; }
   public Color SelectionBackColor{set; get; }
   public Color SelectionForeColor{set; get; }
   public override ISite Site{set; get; } // overrides Control
   public GridTableStylesCollection TableStyles{get; }
   public override string Text{set; get; } // overrides Control
   public object this{set; get; }
   public object this{set; get; }
   public int VisibleColumnCount{get; }
   public int VisibleRowCount{get; }
// Protected Instance Properties
   protected override Size DefaultSize{get; } // overrides Control
   protected ScrollBar HorizScrollBar{get; }
   protected internal CurrencyManager ListManager{set; get; }
   protected ScrollBar VertScrollBar{get; }
// Public Instance Methods
   public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber);  // implements IDataGridEditingService
   public void BeginInit();  // implements System.ComponentModel.ISupportInitialize
   public void Collapse(int row);
   public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, 
        bool shouldAbort);  // implements IDataGridEditingService
   public void EndInit();  // implements System.ComponentModel.ISupportInitialize
   public void Expand(int row);
   public Rectangle GetCellBounds(DataGridCell dgc);
   public Rectangle GetCellBounds(int row, int col);
   public Rectangle GetCurrentCellBounds();
   public HitTestInfo HitTest(int x, int y);
   public HitTestInfo HitTest(System.Drawing.Point position);
   public bool IsExpanded(int rowNumber);
   public bool IsSelected(int row);
   public void NavigateBack();
   public void NavigateTo(int rowNumber, string relationName);
   public void ResetAlternatingBackColor();
   public override void ResetBackColor();  // overrides Control
   public override void ResetForeColor();  // overrides Control
   public void ResetGridLineColor();
   public void ResetHeaderBackColor();
   public void ResetHeaderFont();
   public void ResetHeaderForeColor();
   public void ResetLinkColor();
   public void ResetLinkHoverColor();
   public void ResetSelectionBackColor();
   public void ResetSelectionForeColor();
   public void Select(int row);
   public void SetDataBinding(object dataSource, string dataMember);
   public void SubObjectsSiteChange(bool site);
   public void UnSelect(int row);
// Protected Instance Methods
   protected virtual void CancelEditing();
   protected internal virtual void ColumnStartedEditing(Control editingControl);
   protected internal virtual void ColumnStartedEditing(System.Drawing.Rectangle bounds);
   protected override AccessibleObject CreateAccessibilityInstance();  // overrides Control
   protected virtual DataGridColumnStyle CreateGridColumn(System.ComponentModel.PropertyDescriptor prop);
   protected virtual DataGridColumnStyle CreateGridColumn(System.ComponentModel.PropertyDescriptor prop,
        bool isDefault);
   protected override void Dispose(bool disposing);  // overrides Control
   protected virtual string GetOutputTextDelimiter();
   protected virtual void GridHScrolled(object sender, ScrollEventArgs se);
   protected virtual void GridVScrolled(object sender, ScrollEventArgs se);
   protected virtual void OnAllowNavigationChanged(EventArgs e);
   protected void OnBackButtonClicked(object sender, EventArgs e);
   protected override void OnBackColorChanged(EventArgs e);  // overrides Control
   protected virtual void OnBackgroundColorChanged(EventArgs e);
   protected override void OnBindingContextChanged(EventArgs e);  // overrides Control
   protected virtual void OnBorderStyleChanged(EventArgs e);
   protected virtual void OnCaptionVisibleChanged(EventArgs e);
   protected virtual void OnCurrentCellChanged(EventArgs e);
   protected virtual void OnDataSourceChanged(EventArgs e);
   protected override void OnEnter(EventArgs e);  // overrides Control
   protected virtual void OnFlatModeChanged(EventArgs e);
   protected override void OnFontChanged(EventArgs e);  // overrides Control
   protected override void OnForeColorChanged(EventArgs e);  // overrides Control
   protected override void OnHandleCreated(EventArgs e);  // overrides Control
   protected override void OnHandleDestroyed(EventArgs e);  // overrides Control
   protected override void OnKeyDown(KeyEventArgs ke);  // overrides Control
   protected override void OnKeyPress(KeyPressEventArgs kpe);  // overrides Control
   protected override void OnLayout(LayoutEventArgs levent);  // overrides Control
   protected override void OnLeave(EventArgs e);  // overrides Control
   protected override void OnMouseDown(MouseEventArgs e);  // overrides Control
   protected override void OnMouseLeave(EventArgs e);  // overrides Control
   protected override void OnMouseMove(MouseEventArgs e);  // overrides Control
   protected override void OnMouseUp(MouseEventArgs e);  // overrides Control
   protected override void OnMouseWheel(MouseEventArgs e);  // overrides Control
   protected void OnNavigate(NavigateEventArgs e);
   protected override void OnPaint(PaintEventArgs pe);  // overrides Control
   protected override void OnPaintBackground(PaintEventArgs ebe);  // overrides Control
   protected virtual void OnParentRowsLabelStyleChanged(EventArgs e);
   protected virtual void OnParentRowsVisibleChanged(EventArgs e);
   protected virtual void OnReadOnlyChanged(EventArgs e);
   protected override void OnResize(EventArgs e);  // overrides Control
   protected void OnRowHeaderClick(EventArgs e);
   protected void OnScroll(EventArgs e);
   protected void OnShowParentDetailsButtonClicked(object sender, EventArgs e);
   protected override bool ProcessDialogKey(Keys keyData);  // overrides Control
   protected bool ProcessGridKey(KeyEventArgs ke);
   protected override bool ProcessKeyPreview(ref Message m);  // overrides Control
   protected bool ProcessTabKey(Keys keyData);
   protected void ResetSelection();
   protected virtual bool ShouldSerializeAlternatingBackColor();
   protected virtual bool ShouldSerializeBackgroundColor();
   protected virtual bool ShouldSerializeCaptionBackColor();
   protected virtual bool ShouldSerializeCaptionForeColor();
   protected virtual bool ShouldSerializeGridLineColor();
   protected virtual bool ShouldSerializeHeaderBackColor();
   protected bool ShouldSerializeHeaderFont();
   protected virtual bool ShouldSerializeHeaderForeColor();
   protected virtual bool ShouldSerializeLinkHoverColor();
   protected virtual bool ShouldSerializeParentRowsBackColor();
   protected virtual bool ShouldSerializeParentRowsForeColor();
   protected bool ShouldSerializePreferredRowHeight();
   protected bool ShouldSerializeSelectionBackColor();
   protected virtual bool ShouldSerializeSelectionForeColor();
// Events
   public event EventHandler AllowNavigationChanged;
   public event EventHandler BackButtonClick;
   public event EventHandler BackgroundColorChanged;
   public event EventHandler BorderStyleChanged;
   public event EventHandler CaptionVisibleChanged;
   public event EventHandler CurrentCellChanged;
   public event EventHandler DataSourceChanged;
   public event EventHandler FlatModeChanged;
   public event NavigateEventHandler Navigate;
   public event EventHandler ParentRowsLabelStyleChanged;
   public event EventHandler ParentRowsVisibleChanged;
   public event EventHandler ReadOnlyChanged;
   public event EventHandler Scroll;
   public event EventHandler ShowParentDetailsButtonClick;
}

Hierarchy

System.Object System.MarshalByRefObject System.ComponentModel.Component(System.ComponentModel.IComponen, System.IDisposable) Control(IOleContro, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject, IOleWindow, IViewObject, IViewObject2, IPersist, IPersistStreamInit, IPersistPropertyBag, IPersistStorage, IQuickActivate, System.ComponentModel.ISynchronizeInvoke, IWin32Window) DataGrid(System.ComponentModel.ISupportInitializ, IDataGridEditingService)

Returned By

DataGridTableStyle.DataGrid

Passed To

DataGridColumnStyle.{SetDataGrid(), SetDataGridInColumn()}, DataGridTableStyle.DataGrid, DataGridTextBox.SetDataGrid()

    [ Team LiB ] Previous Section Next Section