aardio 官方社区

用户名  找回密码
 注册会员

QQ登录

只需一步,快速开始

帖子
查看: 10768|回复: 1

listview怎么实现仅对新增加的行编辑

[复制链接]

4

主题

12

回帖

5773

积分

六级会员

积分
5773
QQ
发表于 2013-5-7 17:02:34 | 显示全部楼层 |阅读模式
要求效果:只能编辑新增加的行,已存在的行不能编辑
  1. //listview原地编辑效果
  2. //范例参考 http://bbs.aardio.com/thread-5446-1-1.html
  3. import win.ui;
  4. /*DSG{{*/
  5. var winform = ..win.form( bottom=300;parent=...;text="listview原地编辑效果 by adsadss ";right=522 )
  6. winform.add(
  7. button={ bottom=284;right=492;left=374;top=243;z=3;text="增加一行";cls="button" };
  8. static={ bottom=278;color=255;right=498;left=28;top=228;font=LOGFONT( h=-14;weight=700 );transparent=1;text="static";z=2;cls="static" };
  9. listview={ dr=1;dl=1;bgcolor=16777215;right=505;left=26;dt=1;db=1;cls="listview";bottom=217;top=23;z=1;gridLines=1;edge=1;fullRow=1 }
  10. )
  11. /*}}*/

  12. winform.button.oncommand = function(id,event){
  13.         //winform.msgbox( winform.button.text );
  14.         var index = tostring(winform.listview.count+1);
  15.         winform.listview.addItem({index;"好";"很好";});
  16.        
  17. }


  18. winform.static.text=/*
  19. 点击单元格开始编辑。按回车键结束编辑。
  20. listview必须有fullRow=1属性。
  21. */
  22. winform.listview.insertColumn("测试项1",80)
  23. winform.listview.insertColumn("测试项2",100)
  24. winform.listview.insertColumn("测试项3",-1)
  25. for(i=1;5;1){
  26.     winform.listview.addItem({tostring(i);"点我1";"点我2"});
  27. }

  28. winform.listview.onnotify = function(id,code,ptr){
  29.    
  30.     if(code=0xFFFFFFFE/*_NM_CLICK*/ ){
  31.         var notifyMessage = winform.listview.getNotifyMessage(code,ptr);
  32.         if( ! notifyMessage.iItem && notifyMessage.iSubItem ) return ;
  33.         
  34.         var edit = winform.listview.editlable
  35.         if( ! edit ){
  36.             winform.listview.addCtrl(
  37.                 editlable = {
  38.                     cls="edit";font = LOGFONT( h = 11 );left = 0;top = 0;
  39.                     right = 50;bottom = 50;autoResize = false ;hide = 1;edge = 1;  
  40.                     wndproc = function( hwnd, message, wParam, lParam ){
  41.                             var update;
  42.                         if( ( message = 0x8/*_WM_KILLFOCUS*/)  || message == 0x101/*_WM_KEYUP*/ && wParam == 0xD/*_VK_RETURN*/  ) {
  43.                             update = true;
  44.                         }
  45.                         elseif(message == 0x201/*_WM_LBUTTONDOWN*/ || message == 0x202/*_WM_LBUTTONUP*/ ){
  46.                                 var x,y = win.getMessagePos(lParam)
  47.                                 var rc = edit.clientRect;  
  48.                                 if( ! ::PtInRect(rc,x,y) ){
  49.                                         update = true;
  50.                                         edit.capture = false;
  51.                                 }
  52.                                 else{
  53.                                         edit.capture = true;
  54.                                 }
  55.                         }
  56.                         
  57.                         if( update ){
  58.                             owner.parent.setItemText( owner.text, owner.listViewNotifyMessage.iItem
  59.                                 , owner.listViewNotifyMessage.iSubItem );
  60.                             owner.show(false);
  61.                         }
  62.                     }  
  63.                 }
  64.             )  
  65.             edit = winform.listview.editlable;
  66.         }
  67.         edit.listViewNotifyMessage = notifyMessage;
  68.         edit.text=winform.listview.getItemText(notifyMessage.iItem,notifyMessage.iSubItem);
  69.         var rc=winform.listview.getItemRect( notifyMessage.iItem,notifyMessage.iSubItem,,2/*_LVIR_LABEL*/ )
  70.         rc.right += 5; rc.bottom += 5;
  71.         edit.setRect(rc);
  72.         edit.show();
  73.         edit.setFocus();
  74.         edit.capture = true;
  75.     }
  76. }

  77. winform.show();  
  78. win.loopMessage();
复制代码

4

主题

12

回帖

5773

积分

六级会员

积分
5773
QQ
 楼主| 发表于 2013-5-7 17:30:22 | 显示全部楼层
有人吗, 帮帮忙,谢谢
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

手机版|未经许可严禁引用或转载本站文章|aardio.com|aardio 官方社区 ( 皖ICP备09012014号 )

GMT+8, 2025-6-17 13:46 , Processed in 0.065852 second(s), 26 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表