首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

stringgrid 新建edit有关问题

2012-04-19 
stringgrid 新建edit问题我想在sg当中 每次单击单元格的时候都会动态生成一个edit输入后将结果显示到cell

stringgrid 新建edit问题
我想在sg当中 每次单击单元格的时候都会动态生成一个edit 输入后 将结果显示到cell当中 ,
TEdit *ed=new TEdit(Form7);//frm_apply为窗体名
ed->Name=String("edit1");
ed->Parent=Form7->StringGrid1;//pnl_act为Panel名
ed->Top=50;
ed->Left=50;
ed->Height=50;
ed->Width=50;
ed->Visible=true;
Form7->StringGrid1->Cells[1][1]=ed->Text;
代码是这样,这样的话 当我单击另外的单元格的时候会报错 我就加了delete ed; 这样的话 也不行 生成的edit很快会不见了,我想知道如何去每次单击一个单元格的时候生成一个edit 求指教,谢谢

[解决办法]
你这个思路有问题。程序一开始就创建一个Edit,并将其隐藏。然后在单击StringGrid的单元格时,将其显示出来,用完以后再将其隐藏就行了。不需要频繁的创建和销毁Edit
[解决办法]

C/C++ code
void __fastcall TFormGlxtSetWarrant::StringGrid1SelectCell(TObject *Sender,    int ACol, int ARow, bool &CanSelect){    TStringGrid *sg = dynamic_cast<TStringGrid*>(Sender);    if (!sg)        return;    sg->Perform(WM_CANCELMODE, 0, 0);    TRect R = sg->CellRect(ACol, ARow);    TPoint org = ScreenToClient(sg->ClientToScreen(TPoint(R.Left, R.Top)));    Edit1->SetBounds(org.x, org.y, R.right - R.left, StringGrid1->RowHeights [sg->Row]);    Edit1->Show();    Edit1->BringToFront();    Edit1->SetFocus();    Edit1->Text = "";    Edit1->Text = StringGrid1->Cells [ACol][ARow];}void __fastcall TFormGlxtSetWarrant::Edit1Exit(TObject *Sender){    StringGrid1->Cells [StringGrid1->Col][StringGrid1->Row] = Edit1->Text ;    Edit1->Visible = false;} 

热点排行