TGridPanel使用的问题

leegoex 2013-03-23 05:12:51
我从TGridPanel派生了一个类,通过动态的方式给每个单元添加控件。这个类有个自定义的初始化函数,代码如下

void CMyGrid::InitGrid()
{
Width = 448;
Height = 245;

int nColumnIndex = 0;
int nRowIndex = 0;
//添加列
for(nColumnIndex = 0; nColumnIndex < 4; ++nColumnIndex)
{
TColumnItem *pNewColumn = ColumnCollection->Add();
pNewColumn->SizeStyle = ssAbsolute;
pNewColumn->Value = nColumnIndex?136:40;
}
//添加行
for(nRowIndex = 0; nRowIndex < 7; ++nRowIndex)
{
TRowItem *pNewRow = RowCollection->Add();
pNewRow->SizeStyle = ssAbsolute;
pNewRow->Value = 35;
}
//初始化第一列
for(nRowIndex = 0; nRowIndex < 7; ++nRowIndex)
{
TLabel* plblText = new TLabel(this);
plblText->Parent = this;
plblText->Align = alClient;
plblText->Alignment = taCenter;
plblText->Layout = tlCenter;

switch(nRowIndex)
{
case 0: plblText->Caption="一"; break;
case 1: plblText->Caption="二"; break;
case 2: plblText->Caption="三"; break;
case 3: plblText->Caption="四"; break;
case 4: plblText->Caption="五"; break;
case 5: plblText->Caption="六"; break;
case 6: plblText->Caption="七"; break;
}

TControlItem* pNewItem = ControlCollection->Add();

pNewItem->Column = 0;
pNewItem->Row = nRowIndex;
pNewItem->Control = plblText;
}
}

我想实现的效果是:在每一行的第一列显示它的编号,但实际的效果却是:

这该怎么处理呢?谢谢各位了!我用的是XE2
...全文
494 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

13,871

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧