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/



  • 相关阅读:
    Extjs面板和布局初探
    XAMPP下apache部署网站,多个虚拟机(空间)配置
    安全配置织梦系统初探参考[转载]
    windows系统如何真正隐藏文件夹[转载]
    Siamese-RPN论文阅读
    线段树求和
    算法要点随记
    map使用示例
    算法准备之c++ sort使用示例
    编程要点随记
  • 原文地址:https://www.cnblogs.com/actionke/p/4192632.html
Copyright © 2011-2022 走看看