Example
The following example checks the fpSpread control for selected blocks and turns the background color of the selected cells to blue when the user chooses a command button.
C++
void CTestDlg::OnButton1()
{
int i;
VARIANT c, r, c2, r2;
if(m_Spread1.GetIsBlockSelected( ) || m_Spread1.GetSelectionCount( ))
{
// Set the background color for each cell
// block to blue
for( i=0; i<m_Spread1.GetSelectionCount( ); i++)
{
m_Spread1.GetSelection(i, &c, &r, &c2, &r2);
m_Spread1.SetCol(c.lVal);
m_Spread1.SetCol2(c2.lVal);
m_Spread1.SetRow(r.lVal);
m_Spread1.SetRow2(r2.lVal);
m_Spread1.SetBlockMode(TRUE);
m_Spread1.SetBackColor(RGB(0,0,255));
m_Spread1.SetBlockMode(FALSE);
}
}
}
Visual Basic
Private Sub Command1_Click()
Dim x As Long
' Get whether a block of cells is selected
If fpSpread1.IsBlockSelected Or fpSpread1.SelectionCount Then
' Set the background color for each cell block to blue
fpSpread1.BlockMode = True
For x = 0 To fpSpread1.SelectionCount - 1
fpSpread1.GetSelection x, c, r, c2, r2
fpSpread1.Col = c
fpSpread1.Col2 = c2
fpSpread1.Row = r
fpSpread1.Row2 = r2
' blue, RGB(0,0,255)
fpSpread1.BackColor = &HFF0000
Next x
fpSpread1.BlockMode = False
End If
End Sub