zoukankan      html  css  js  c++  java
  • 让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/



  • 相关阅读:
    Java内存模型
    Redis的复制特性
    Redis数据持久化
    Java的三种代理模式
    设计模式—模板方法模式
    设计模式—观察者模式
    web性能优化之:no-cache与must-revalidate深入探究
    JWT
    数值每三位加逗号
    Webpack 打包优化之速度篇
  • 原文地址:https://www.cnblogs.com/actionke/p/4192632.html
Copyright © 2011-2022 走看看