property Grid.BackColor as Color
Retrieves or sets a value that indicates the control's background color.

 TypeDescription 
   Color A color expression that indicates the control's background color  

Use the BackColor property to set the control's background color. If the control contains locked columns, ( if the CountLockedColumns property is grater than 0, a locked column is a column non scrolable ), use the BackColorLock property to specify the background color for locked columns.  Use the CellBackColor property to set the cell's background color. Use the ItemBackColor property to specify the item's background color. The control highlights the selected items only if the SelBackColor and BackColor properties have different values, and the SelForeColor and ForeColor properties have different values. Use the Def(exCellBackColor) property to specify the background color for all cells in the column.

The following VB sample sets the background color for the first column:

With Grid1.Columns(0)
    .Def(exCellBackColor) = RGB(240, 240, 120)
End With 

The following C++ sample sets the background color for the first column:

#include "Column.h"
#include "Columns.h"
CColumns columns = m_grid.GetColumns();
CColumn column = columns.GetItem( COleVariant( long(0) ) );
column.SetDef(4, COleVariant( (long)RGB(240,240,240 ) ) );

The following VB.NET sample sets the background color for the first column:

With AxGrid1.Columns(0)
    .Def(EXGRIDLib.DefColumnEnum.exCellBackColor) = ToUInt32(Color.FromArgb(240, 240, 240))
End With

where the ToUInt32 function converts a Color expression to OLE_COLOR expression:

Shared Function ToUInt32(ByVal c As Color) As UInt32
    Dim i As Long
    i = c.R
    i = i + 256 * c.G
    i = i + 256 * 256 * c.B
    ToUInt32 = Convert.ToUInt32(i)
End Function

The following C# sample sets the background color for the first column:

axGrid1.Columns[0].set_Def(EXGRIDLib.DefColumnEnum.exCellBackColor, ToUInt32(Color.FromArgb(240, 240, 240))); 

where the ToUInt32 function converts a Color expression to OLE_COLOR expression:

private UInt32 ToUInt32(Color c)
{
	long i;
	i = c.R;
	i = i + 256 * c.G;
	i = i + 256 * 256 * c.B;
	return Convert.ToUInt32(i);
}

The following VFP sample sets the background color for the first column:

with thisform.Grid1.Columns(0)
	.Def(4) = RGB(240,240,240)
endwith

 


Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.