zoukankan      html  css  js  c++  java
  • PopupMenu菜单为ListView的每个Items使用

    最近做一个Case就是遇到这样的事,用一个PopupMenu为Listview的子项使用。下面是代码;写的有点乱,不过能用;

    第一步先在你的你的Form的OnCretae事件中添加代码;

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i:Integer;
    begin
    
      for i:=0 to PopupMenu1.Items.Count -1 do
      begin
         PopupMenu1.Items[i].Visible :=false;
       end;
    
    end;
    //这个循环的作用是初始化PopupMenu的所有子项为不可见;
    procedure TForm1.ListView1ContextPopup(Sender: TObject; MousePos: TPoint;
      var Handled: Boolean);
        var
           i, j, s, a:Integer;
    begin
        ListView1.Update;
       for  i:=0 to ListView1.Items.Count - 1 do
       begin
            if ListView1.Items.Count >0 then
            begin
              for a:=0 to ListView1.Items.Count +1 do
              begin
             if ListView1.SelCount  =0 then
               begin
                 for j :=0 to PopupMenu1.Items.Count -1 do
                   begin
                     PopupMenu1.Items[j].Visible :=False;
                   end;
               end
                  else
                    begin
                      for s:=0 to PopupMenu1.Items.count -1 do
                      begin
                      PopupMenu1.Items[s].Visible :=True;
                      end;
                    end;
            end ;
           // Exit;
            end;
            end;
    end;
    //上面这段代码作用是判断用户选择哪一个ListView的子项,如果是第N个的话当在第N个上面右击鼠标时就会出现PopupMenu菜单,
    //当然选择一个空子项这个PopupMenu菜单是不会显示的;
  • 相关阅读:
    (一)Redis初学教程之安装篇
    Redis常用数据类型
    css
    js常用内置对象、Dom对象、BOM对象
    CSS定位(postion)和移动(float)
    Razor模板引擎(C#版)语法
    虚拟化和反序列化
    id 自增------删除数据后恢复到删除前自增id
    SERVER全局数组
    文件路径操作
  • 原文地址:https://www.cnblogs.com/flay/p/2531422.html
Copyright © 2011-2022 走看看