无法更新listview

时间:2014-06-02 19:55:19

标签: listview autohotkey

在我的GUI中,我有一个listview,我想在其中更改单元格的值。我已经尝试了所有内容,每次调用lv_modify()时它都会返回0,这意味着出现了错误 - 这也意味着更改无法完成......

这是我的示例脚本 - 您应该能够像这样运行它。右键单击任何listview控件中的项目,然后尝试编辑文本。消息框报告变量。

我哪里错了?

;-------- http://ahkscript.org/boards/viewtopic.php?f=5&t=3656 ---
MODIFIED=20140531
Tabnumber:=1
gui, mainui:new, hwndmainui, ListViews On Tab2
gui,add, Tab2,  vTabnumber AltSubmit, one|two|three|four
gui,tab, one
gui,add, listview, r5 vlistview1 hwndlistview1 gListViewEvents -Readonly +altsubmit -multi, col1|col2
LV_Add("", "bob", "harry")
LV_Add("", "first", "111111111")
gosub,width1
gui,tab, two
gui,add, listview, r5 vlistview2 hwndlistview2 gListViewEvents -Readonly +altsubmit -multi, col1|col2
LV_Add("", "george", "harvey")
LV_Add("", "second", "222222")
gosub,width1
gui, tab, three
gui,add, listview, r5 vlistview3 hwndlistview3 gListViewEvents -Readonly +altsubmit -multi, col1|col2
LV_Add("", "michael", "richard")
LV_Add("", "third", "33333333")
gosub,width1
gui, tab, four
gui,add, listview, r5 vlistview4 hwndlistview4 gListViewEvents -Readonly +altsubmit -multi, col1|col2
LV_Add("", "harold", "marcel")
LV_Add("", "fourth", "44444")
gosub,width1
gui, show

RETURN

mainuiGuiclose:
exitapp

width1:
T1=70
T2=140
LV_ModifyCol(1,T1)
LV_ModifyCol(2,T2)
return


LISTVIEWEVENTS:
current_listview := a_guicontrol 
gui, mainui:listview, %current_listview%    

if(A_GuiEvent == "Normal"){ 
    LV_GetText(current_var, A_EventInfo, 1) 
    LV_GetText(current_val, A_EventInfo, 2)
    msgbox, %current_var% : %current_val%
}   
if(A_GuiEvent == "RightClick"){
    mousegetpos, mousex, mousey
    LV_GetText(current_var, A_EventInfo, 1) 
    LV_GetText(current_val, A_EventInfo, 2)
    current_row := A_EventInfo
    gosub, EDITListViewVALUE
}
RETURN

;------------------------------------------------------------------------------------
EDITListViewVALUE:  

gui, %current_listview%Editor:new
gui, +resize
gui, add, text, , Edit Value
gui, add, edit, w300 h50 -wrap r1 vnew_%current_listview%, %current_val% 
Gui, Font, S10 CPurple Bold
Gui, Add, Button,   x12 gListViewEditorACCEPT default, Accept
Gui, Add, Button,   x+4 gListViewEditorCANCEL, Cancel
Gui, Show, center, Data Editor
Return

ListViewEditorACCEPT:
gui, %current_listview%Editor:submit
;now assign the new value to it's matching variable
%current_var% := new_%current_listview%

msgbox % "Current Row=" . current_row . "`rListView=" . current_listview . "`rOld Value=" . current_val . "`rNew Value=" . new_%current_listview%

gui, mainui:listview, %current_listview%    
msgbox % "Success=" . lv_modify(current_row, "Col1", new_%current_listview%)    
Return

ListViewEditorCANCEL:
gui, %current_listview%Editor:cancel
Return

[更新]

尽管在lv_modify之前调用'gui,mainui:listview,%current_listview%',但看起来对默认列表视图的访问仍然丢失。但是lv_modify如果没有在ListViewEditorACCEPT子中调用,则可以正常工作。

1 个答案:

答案 0 :(得分:1)

啊!诀窍是将线程操作重置回主GUI。当我们打开第二个GUI窗口时,它接管了线程操作。

这是ListViewEditorACCEPT sub。

的尾端
;Reset the thread operation to the main GUI
gui, mainui:default

;Now reset the default listview
gui, mainui:listview, %current_listview%
相关问题