专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > C++ Builder

stringgrid 新建edit有关问题

发布时间:2011-06-28 12:20:11 文章来源:www.iduyao.cn 采编人员:星星草
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;
}
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: