Skip to content

DataGridView

Radu Martin edited this page Apr 15, 2017 · 15 revisions

Column generation

GenerateColumns(object DataSource, params ColumnDataDescriptor[] Columns)

ColumnDataDescriptor helps the generator to recognize the created column:

ColumnDataDescriptor(string HeaderText, DataColumn Column, 
    ColumnEditorMode Mode = ColumnEditorMode.Auto,
    EditorDataStyle? Style = null, 
    float? FillWeight = null, 
    object NullValue = null, 
    bool IsReadOnly = false,
    object DataSource = null, 
    string ValueMember = null, 
    string DisplayMember = null,
    GetListBoxItemsDelegate GetListBoxItemsMethod = null,
    FormatValueDelegate FormatValueMethod = null)

Adding read-only text and check columns

AddTextColumn(string DataPropertyName, string HeaderText, string ToolTipText)
AddCheckColumn(string DataPropertyName, string HeaderText, string ToolTipText)

where DataPropertyName is a name of property or column name,
HeaderText is a text of colum header,
ToolTipText is a text for ToolTip on column header.

Preparations

Following methods have been implemented for preparing the DataGridView for displaying or editing data:

PrepareStyleForShowingData();
PrepareStyleForEditingData();
PrepareStyleForShowingReportData();

Visual styles

DataGridView can show the coloured DataRowState on his row Header

AddDataRowStateDrawingInRowHeaders(
      Color chgColor, 
      Color insColor, 
      bool IsGradient)

where chgColor is a colour for changed rows,
insColor is a colour for added rows,
and IsGradient is a flag fow drawing style.

For example:

dataGrid.AddDataRowStateDrawingInRowHeaders(
    Color.FromArgb(0x99, 0xFF, 0xCC, 0x33),
    Color.FromArgb(0x99, 0xFF, 0x66, 0x00), 
    true);

AddDataRowStateDrawingInRowHeaders

In addition, there are two versions of the AddDataRowStateDrawingInRowHeaders method without parameters that use default colours.