Changing Colors and Fonts of DataGrid Cells

Changing Colors and Fonts of DataGrid Cells

Attributes such as the foreground color, background color, and fontsof cells in Sheridan’s DataGrid can easily be changed by setting RowCellxxxxproperties such as RowCellForeColor, RowCellBackColor, RowCellItalic, andso on from within the RowLoaded event. This event fires when the grid initiallyloads records and while scrolling through rows, allowing you to set variousproperties for each row in the DataGrid. This code will set column 0’sbackground color to red, text color to white, and font to italics:

 Sub SSDataGrid1_RowLoaded (BookMark As String, _ RowNum As Long) SSDataGrid1.RowCellForeColor(0) = _ RGB(255,255,255) 'set foreground to white SSDataGrid1.RowCellBackColor(0) = RGB(255,0,0) 'set background to red SSDataGrid1.RowCellItalics(0) = True 'set font to italics End Sub 

Another way to change the appearance of individual cells in theDataGrid is to set the EvalRowNumber property to a specific row numberand then set the appropriate RowCellxxxx properties. This illustrates thismethod in the Click event of a Command button:

 Sub Command1_Click() SSDataGrid1.EvalRowNumber = 10 'row to be manipulated SSDataGrid1.RowCellForeColor(2) = _ RGB(255,255,255) 'set foreground at column 2 to white SSDataGrid1.RowCellBackColor(2) = RGB(255,0,0) 'set background to red SSDataGrid1.RowCellItalics(2) = True 'set font to italics End Sub 


Share the Post: