在stringGrid 中如何在一列中定义一个下拉框,这样在输入性别时就可以选择了。怎么实现?

解决方案 »

  1.   

    你干脆放置一个combobox控件,然后一直往下移动,
    输入的时候可以在combobox中选择就可以了撒
      

  2.   

    不错,就用Combobox, 又快又好又省钱(时间就是金钱)
      

  3.   

    To  cqwty(笨小孩) 这好像实现有点困难,至少对我来讲。那个移动怎么实现?我想我的方法应该可以,也应该有人用过。请指点。谢谢啦!
      

  4.   

    窗体中添加:StringGrid1,ComboBox1procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    var r:TRect;
    begin
        r:=StringGrid1.CellRect(ACol,ARow);
        StringGrid1.DefaultRowHeight:=ComboBox1.Height;
        ComboBox1.Left:=StringGrid1.Left + R.Left + 1;
        ComboBox1.Top:=StringGrid1.Top + R.Top + 1;
        ComboBox1.Width:=R.Right - R.Left;
    end;
      

  5.   

    首先放一Panel1,在此Panel1上放一SpeedButton,然后设置Panel1的AutoSize为TRUE;
    Panel1的BevelOuter为bvNone,目的使这个Panel1彻底地没有留下痕迹。
    再在FROM上放ComboBox1,在它的Items属性上随便放些值。//设置StringGrid的Column要显示的字符。
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      StringGrid1.Rows[0].Add('for you want');
      StringGrid1.Rows[0].Add('測試標准');
      StringGrid1.Rows[0].Add('panel');
    end;
    //在StringGrid的自画事件中,将两个控件摆到StringGrid相应的Cells中
    //Panel1.Top:=Rect.Top+StringGrid1.Top+2中的“+2”无非是使控件显示的位置更加准确。
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
    if (gdFocused in State) then
      begin
        if (StringGrid1.Cells[Acol,0]='測試標准') then
        begin
          ComboBox1.Left:=Rect.Left+StringGrid1.Left;
          ComboBox1.Top:=Rect.Top+StringGrid1.Top+3;
          ComboBox1.Width:=Rect.Right-Rect.Left+2;
          ComboBox1.Visible:=true;
          ComboBox1.SetFocus;
          ComboBox1.Text:=StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row];
        end
        else
          ComboBox1.Visible := False;
        if (StringGrid1.Cells[Acol,0]='panel') then
        begin
          Panel1.Left:=Rect.Right + StringGrid1.Left - Panel1.Width;
          Panel1.Top:=Rect.Top+StringGrid1.Top+2;
          Panel1.Height:=Rect.Bottom-Rect.Top;
          Panel1.Visible:=True;
        end
        else
          Panel1.Visible := False;
      end;
    end;
    //将选取到的ComboBox值赋值到StringGrid相应的Cells中。
    procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
      StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=ComboBox1.Items[ComboBox1.ItemIndex];
    end;//在SpeedButton1的点击事件中做你想到做的事情。