JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Using the DataGrid Class

We've already put the data grid control to work in the previous chapter, and in the DataBinding example in this chapter. This control displays a data table all at once in a scrollable grid format and is supported by the DataGrid class. Here is the inheritance hierarchy of this class:

Object
   MarshalByRefObject
      Component
         Control
            DataGrid

You also can display hierarchical datasets in data grids. In a hierarchical dataset, fields themselves can display Web-like links to child tables. You can click a link to navigate to the child table. When a child table is displayed, a back button appears in the caption that can be clicked to navigate back to the parent table.

You can find the more notable public properties of DataGrid objects in Table 21.6, their more notable methods in Table 21.7, and the more notable events in Table 21.8. Note that as with other Windows controls, I am not listing the notable properties, methods, and events ListBox inherits from the Control class, such as the Click event—you can see all that in Chapter 5, Tables 5.1, 5.2, and 5.3.

Table 21.6: Noteworthy public properties of DataGrid objects.

Property

Means

AllowNavigation

Gets/sets if navigation is possible.

AllowSorting

Gets/sets if the grid can be sorted when the user clicks a column header.

AlternatingBackColor

Gets/sets the background color of alternating rows.

BackColor

Gets/sets the background color of the grid.

BackgroundColor

Gets/sets the color of the non-data part of the data grid.

BorderStyle

Gets/sets the grid's style of border.

CaptionBackColor

Gets/sets the caption's background color.

CaptionFont

Gets/sets the caption's font.

CaptionForeColor

Gets/sets the caption's foreground color.

CaptionText

Gets/sets the caption's text.

CaptionVisible

Gets/sets if the caption is visible.

ColumnHeadersVisible

Gets/sets if the parent rows of a table are visible.

CurrentCell

Gets/sets which cell has the focus.

CurrentRowIndex

Gets/sets the index of the selected row.

DataMember

Gets/sets the table or list of data the data grid should display.

DataSource

Gets/sets the data grid's data source, such as a dataset.

FirstVisibleColumn

Gets the index of the first column visible in the grid.

FlatMode

Gets/sets if the grid is shown flat.

ForeColor

Gets/sets the foreground color.

GridLineColor

Gets/sets the color of grid lines.

GridLineStyle

Gets/sets the grid line style.

HeaderBackColor

Gets/sets the background color of headers.

HeaderFont

Gets/sets the font used for headers.

HeaderForeColor

Gets/sets the foreground color of headers.

Item

Gets/sets the value in a particular cell.

LinkColor

Gets/sets the color of links to child tables.

LinkHoverColor

Gets/sets the color of links when the mouse moves over it.

ParentRowsBackColor

Gets/sets the background color of parent rows.

ParentRowsForeColor

Gets/sets the foreground color of parent rows.

ParentRowsLabelStyle

Gets/sets the style for parent row labels.

ParentRowsVisible

Gets/sets if parent rows are visible.

PreferredColumnWidth

Gets/sets the width of the grid columns (measured in pixels).

PreferredRowHeight

Gets/sets the preferred row height.

ReadOnly

Gets/sets if the grid is read-only.

RowHeadersVisible

Gets/sets if row headers are visible.

RowHeaderWidth

Gets/sets the width of row headers.

SelectionBackColor

Gets/sets selected cell's background color.

SelectionForeColor

Gets/sets selected cell's foreground color.

TableStyles

Gets the table styles in the data grid.

VisibleColumnCount

Gets the number of visible columns.

VisibleRowCount

Gets the number of visible rows.

Table 21.7: Noteworthy public methods of DataGrid objects.

Method

Means

BeginEdit

Allows editing.

Collapse

Collapses child table relations.

EndEdit

Ends editing operations.

Expand

Displays child relations.

GetCellBounds

Gets the Rectangle object that specifies a cell.

GetCurrentCellBounds

Gets a Rectangle object that specifies the selected cell.

HitTest

Coordinates mouse position with points in the data grid.

IsExpanded

Gets whether a row is expanded or collapsed.

IsSelected

Gets whether a row is selected.

NavigateBack

Navigates to the previous table that was shown in the grid.

NavigateTo

Navigates to a specific table.

Select

Makes a selection.

SetDataBinding

Sets both the DataSource and DataMember properties. Used at run time.

UnSelect

Unselects a row.

Table 21.8: Noteworthy public events of DataGrid objects.

Event

Means

AllowNavigationChanged

Occurs when the AllowNavigation property changes.

CurrentCellChanged

Occurs when the CurrentCell property changes.

DataSourceChanged

Occurs when the DataSource property value changes.

FlatModeChanged

Occurs when the FlatMode changes.

Navigate

Occurs when the user navigates to a new table.

ParentRowsVisibleChanged

Occurs when the ParentRowsVisible property value changes.

ReadOnlyChanged

Occurs when the ReadOnly property value changes.

Scroll

Occurs when the data grid is scrolled.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor