我需要显示和修改一些数据,不是从数据库来得。
我用stringgrid来显示和修改,我想在修改的时候,有下拉框可以选择数据。
但是stringgrid好像不能这样。
请问有什么办法达到我的要求?除了stringgrid还有什么可以用?

解决方案 »

  1.   

    可以的,在stringgrid的SelectCell事件中动态计算combobox的位置,把值付给cell
    例:procedure Tfrm_makerep.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);begin
           if ComboBox1.Visible then
        begin
            StringGrid1.Cells[3,iRow] := ComboBox1.text;
            ComboBox1.Visible := false;                                    
        end
        else if Combobox2.Visible then                               
        begin                                                          
           StringGrid1.Cells[4,iRow] := ComboBox2.Text;
           ComboBox2.Visible := false;
        end
        else if Edit1.Visible then
        begin
            StringGrid1.Cells[5,iRow] := Edit1.Text;
            Edit1.Visible := false;
        end;
        iCol:=ACol;
        iRow:=ARow;
        if iCount = 0 then
            exit;
          if ACol = 0 then
      begin
        if StringGrid1.Cells[0,ARow]=chr(1) then
          StringGrid1.Cells[0,ARow]:=''
        else
          StringGrid1.Cells[0,ARow]:=chr(1);
      end;
         if ACol = 3 then
        begin
            ComboBox1.Top := StringGrid1.top + (Arow
                            - StringGrid1.TopRow+1)*(StringGrid1.RowHeights[1]+1)+2;
            ComboBox1.ItemIndex:=ComboBox1.Items.IndexOf(StringGrid1.Cells[3,ARow]);
            ComboBox1.Visible := true;
        end
        else if ACol = 4 then
        begin
            ComboBox2.Top := StringGrid1.top + (Arow
                            - StringGrid1.TopRow+1)*(StringGrid1.RowHeights[1]+1)+2;
            ComboBox2.ItemIndex:=ComboBox2.Items.IndexOf(StringGrid1.Cells[4,ARow]);
            //ComboBox2.Text := StringGrid1.Cells[4,ARow];
            ComboBox2.Visible := true;
        end
        else if ACol = 5 then
        begin
            Edit1.Top := StringGrid1.top + (Arow
                            - StringGrid1.TopRow+1)*(StringGrid1.RowHeights[1]+1)+2;        Edit1.Text := StringGrid1.Cells[5,ARow];
            Edit1.Visible := true;
        end;end;
      

  2.   

    在stringgrid上放combobox
    procedure Tbj_w.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    begin
       if key=#13 then
        begin
         stringgrid1.cells[col,row]:=combobox1.Text;
         combobox1.Visible:=false;
         stringgrid1.SetFocus;
        end;
    end;
    if key=#32  then //处理空格键
      begin
      if stringgrid1.Col=5 then
         combobox1.Visible:=true;
      ....
    end;