StringGrid合并单元格
本帖最后由 maliang799 于 2011-11-21 15:15:18 编辑
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if (ACol == 0)
{
if ( (ARow == 1) || (ARow == 3))
Rect.Bottom = Rect.Bottom + Rect.Height();
if ( (ARow == 2) || (ARow == 4))
Rect.Top = Rect.Bottom;
}
StringGrid1->Canvas->FillRect(Rect);
DrawText(StringGrid1->Canvas->Handle, StringGrid1->Cells[ARow][ACol].c_str(),
StringGrid1->Cells[ARow][ACol].Length() , &Rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
}
void __fastcall TForm1::btn1Click(TObject *Sender)
{
StringGrid1->Cells[1][0] = "1";
StringGrid1->Cells[1][1] = "2";
StringGrid1->Cells[2][1] = "3";
StringGrid1->Cells[3][0] = "4";
StringGrid1->Cells[3][1] = "5";
StringGrid1->Cells[4][1] = "6";
}
void __fastcall TForm1::Button1Click(TObject *Sender)最后加一句就行了
{
StringGrid1->Cells[1][0] = "1";
StringGrid1->Cells[1][1] = "2";
StringGrid1->Cells[2][1] = "3";
StringGrid1->Cells[3][0] = "4";
StringGrid1->Cells[3][1] = "5";
StringGrid1->Cells[4][1] = "6";
StringGrid1->Invalidate();
}