|
要求效果:只能编辑新增加的行,已存在的行不能编辑- //listview原地编辑效果
- //范例参考 http://bbs.aardio.com/thread-5446-1-1.html
- import win.ui;
- /*DSG{{*/
- var winform = ..win.form( bottom=300;parent=...;text="listview原地编辑效果 by adsadss ";right=522 )
- winform.add(
- button={ bottom=284;right=492;left=374;top=243;z=3;text="增加一行";cls="button" };
- 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" };
- 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 }
- )
- /*}}*/
- winform.button.oncommand = function(id,event){
- //winform.msgbox( winform.button.text );
- var index = tostring(winform.listview.count+1);
- winform.listview.addItem({index;"好";"很好";});
-
- }
- winform.static.text=/*
- 点击单元格开始编辑。按回车键结束编辑。
- listview必须有fullRow=1属性。
- */
- winform.listview.insertColumn("测试项1",80)
- winform.listview.insertColumn("测试项2",100)
- winform.listview.insertColumn("测试项3",-1)
- for(i=1;5;1){
- winform.listview.addItem({tostring(i);"点我1";"点我2"});
- }
-
- winform.listview.onnotify = function(id,code,ptr){
-
- if(code=0xFFFFFFFE/*_NM_CLICK*/ ){
- var notifyMessage = winform.listview.getNotifyMessage(code,ptr);
- if( ! notifyMessage.iItem && notifyMessage.iSubItem ) return ;
-
- var edit = winform.listview.editlable
- if( ! edit ){
- winform.listview.addCtrl(
- editlable = {
- cls="edit";font = LOGFONT( h = 11 );left = 0;top = 0;
- right = 50;bottom = 50;autoResize = false ;hide = 1;edge = 1;
- wndproc = function( hwnd, message, wParam, lParam ){
- var update;
- if( ( message = 0x8/*_WM_KILLFOCUS*/) || message == 0x101/*_WM_KEYUP*/ && wParam == 0xD/*_VK_RETURN*/ ) {
- update = true;
- }
- elseif(message == 0x201/*_WM_LBUTTONDOWN*/ || message == 0x202/*_WM_LBUTTONUP*/ ){
- var x,y = win.getMessagePos(lParam)
- var rc = edit.clientRect;
- if( ! ::PtInRect(rc,x,y) ){
- update = true;
- edit.capture = false;
- }
- else{
- edit.capture = true;
- }
- }
-
- if( update ){
- owner.parent.setItemText( owner.text, owner.listViewNotifyMessage.iItem
- , owner.listViewNotifyMessage.iSubItem );
- owner.show(false);
- }
- }
- }
- )
- edit = winform.listview.editlable;
- }
- edit.listViewNotifyMessage = notifyMessage;
- edit.text=winform.listview.getItemText(notifyMessage.iItem,notifyMessage.iSubItem);
- var rc=winform.listview.getItemRect( notifyMessage.iItem,notifyMessage.iSubItem,,2/*_LVIR_LABEL*/ )
- rc.right += 5; rc.bottom += 5;
- edit.setRect(rc);
- edit.show();
- edit.setFocus();
- edit.capture = true;
- }
- }
- winform.show();
- win.loopMessage();
复制代码 |
|