0

我在 StringGrid 中插入 Editbox 时遇到问题。我的表单上有一个 StringGrid 和一个 Editbox。编辑框在选定的列和行中显示得很好,但我只能在选定的单元格中插入一个数字......谁能解释我如何在其中输入更多数字?

天呐!

//Editbox on change event
void __fastcall TForm3::StringGridEditChange(TObject *Sender)
{
    int x,y;

    x = Form3->VariableGrid->Col;
    y = Form3->VariableGrid->Row;

  if (VariableGrid->Col !=2 )
  {
    VariableGrid->Col = 2;
  }
  if (VariableGrid->Row <1 )
  {
    VariableGrid->Row = 1;
    ShowMessage("Prevention!");
  }

  VariableGrid->Cells[VariableGrid->Col][VariableGrid->Row] = StringGridEdit->Text;
  StringGridEdit->Visible = false;
  VariableGrid->SetFocus();

//StringGrid on selectCell event
void __fastcall TForm3::VariableGridSelectCell(TObject *Sender, int ACol, int ARow,
          bool &CanSelect)
{
    if(ACol == 2 && ARow>0)
  {
    TRect R = VariableGrid->CellRect(ACol, ARow);
    R.Left   += VariableGrid->Left;
    R.Right  += VariableGrid->Left;
    R.Top    += VariableGrid->Top;
    R.Bottom += VariableGrid->Top;
    StringGridEdit->Left = R.Left + 1;
    StringGridEdit->Top = R.Top + 1;
    StringGridEdit->Width = (R.Right + 1) - R.Left;
    StringGridEdit->Height = (R.Bottom + 1) - R.Top;
    //Show the editbox
    StringGridEdit->Visible = true;
    StringGridEdit->SetFocus();
  }
  CanSelect = true;
}

在 C++ Builder XE2 中

4

0 回答 0