让StringGrid控件显示下拉菜单

1、效果预览

2、关键代码

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    StringGrid1->ColCount = 4;
    StringGrid1->RowCount = 6;
    StringGrid1->DefaultRowHeight = ComboBox1->Height;
    StringGrid1->RowHeights[0] = 18;
    StringGrid1->ColWidths[2] = 80;
    StringGrid1->Cells[0][0] = "FirstName";
    StringGrid1->Cells[1][0] = "LastName";
    StringGrid1->Cells[2][0] = "SBVLEdit LV1";
    StringGrid1->Cells[3][0] = "Action";

    ComboBox1->Text = "";
    ComboBox1->Items->Add("Teen");
    ComboBox1->Items->Add("Adult");
    ComboBox1->Items->Add("Senior");
    ComboBox1->Visible = False;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
   StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row] = ComboBox1->Items->Strings[ComboBox1->ItemIndex];
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1DblClick(TObject *Sender) //双击事件
{
    TRect r;
    if(StringGrid1->Col == 2)
    {
        int ACol = StringGrid1->Col;
        int ARow = StringGrid1->Row;
        r = StringGrid1->CellRect(ACol,ARow);
        ComboBox1->Top = StringGrid1->Top + r.Top + StringGrid1->GridLineWidth + 1;
        ComboBox1->Left = StringGrid1->Left + r.Left + StringGrid1->GridLineWidth +1;
        ComboBox1->Width = r.Right - r.Left;
        ComboBox1->ItemIndex = ComboBox1->Items->IndexOf(StringGrid1->Cells[ACol][ARow]);
        ComboBox1->Visible = true;
    }
    else
        ComboBox1->Visible = false;
}
//---------------------------------------------------------------------------


参考:http://ymg97526.blog.163.com/blog/static/17365816020135264552765/



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值