Jump to content

GUI Error Next Button


IvanCodin
 Share

Recommended Posts

How can I resolve this error? When I open my script and click the nextbutton to view additional records I see and the following error:

Use GUICtrlDelete to delete items

Or if items were created with UDF functions MAKE sure to pass in handle to control NOT controlid

When searching the forum I found information that indicated I should use the Autoit Window Tool to find the handle. I believe I have determine what the window information is but what do I do with it? I did see in the forums where if you use a UDF function do not switch to a windows function. Is line 53 of the DBtest script is it switching to a windows functions or is it still a UDP function call?

DBtest.au3 is here:

#include <GUIConstants.au3>
#include "_DBlistView.au3"

Opt("GUIOnEventMode", 1); OnEvent mode
Dim $title="Access db Viewer";gui title

Dim $gui = GUICreate($title, 600, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$DB = @ScriptDir & "\test.mdb"
$Query= "SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName"
$Number_of_Records_to_Display = 20
$Listview_Left = 100
$Listview_Top = 50
$Listview_Width = 400
$Listview_Height = 400
$Listview_style = $GUI_SS_DEFAULT_LISTVIEW;default is -1
$Listview_exStyle = $LVS_EX_FULLROWSELECT + $LVS_EX_GRIDLINES;default is -1

$dblv = _createDBlistView($DB,$Query,$Number_of_Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)
$ed1 = GUICtrlCreateEdit('',$Listview_Left,$Listview_Top + $Listview_Height,$Listview_Width,100)
GUISetState ()
$selected = -1
$lastselected = -1
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
While 1
    Sleep(100); Idle around

    #cs
        $selected = _GUICtrlListView_GetSelectedIndices($dblv,true)
        
        if $selected[0] > 0 Then;if success
        if $selected[1] <> $lastselected Then
        $lastselected = $selected[1]
        MsgBox(0,'changed selection to','item ' & $lastselected)
        EndIf
        
        EndIf
    #ce
WEnd
;Func ListView_DoubleClick()
;ConsoleWrite("Button_DblClick" & @LF)
;Local $itemIndex = _GUICtrlListView_GetNextItem ($dblv)
    Local $text ,$ItText
    $text = GUICtrlRead($ed1);read the text in the edit
    $ItText = _GUICtrlListView_GetItemTextString($dblv,-1);read the items in the row double clicked
;Item text could be spilt into its parts using stringsplit
    $text &= $ItText;add the items string to the text
    GUICtrlSetData($ed1,$text & @CRLF);write the text into the edit;
    
;EndFunc ;==>Button_Click


Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event
    $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
        Case $wParam = $dblv
            Select
                Case $event = $NM_CLICK
               ;ListView_Click();func could be written to handle this
                Case $event = $NM_DBLCLK
                    ListView_DoubleClick()
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
EndFunc;



Func CLOSEClicked()
    Exit
EndFunc

_DBListView.au3 is here:

#Include <GuiListView.au3>

Dim $conn,$DB,$Query,$rs,$tableField_Names,$data
Dim $dblistview,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height
Dim $prev_Button,$next_Button,$pageing_label,$i_StartingRecord=0,$i_OffsetRecord=0,$iStop,$iRows
Dim $table

Func Build_ListViewItems()
If $dblistview Then _GUICtrlListView_DeleteAllItems ($dblistview)
        
$iRows = UBound($data, 1)-1 
$iCols = UBound($data, 2)-1
If $iRows > ($i_OffsetRecord + $i_StartingRecord) Then 
$iStop = $i_OffsetRecord + $i_StartingRecord - 1 
Else 
$iStop = $iRows
EndIf 
For $iRowLoop = $i_StartingRecord to $iStop
    $builcols=""
    For $iColLoop = 0 to $iCols 
    $builcols&=$data[$iRowLoop][$iColLoop] & "|"    
    Next 
GUICtrlCreateListViewItem($builcols, $dblistview)
GUICtrlSetOnEvent(-1, "") 
;add your on-click function here
Next 
GUICtrlSetData($pageing_label,"Viewing " & $i_OffsetRecord & " records starting at record " & $i_StartingRecord)

EndFunc
Func ListView_DoubleClick()
;ConsoleWrite("Button_DblClick" & @LF)
;Local $itemIndex = _GUICtrlListView_GetNextItem ($dblv)
    Local $text ,$ItText
    $text = GUICtrlRead($ed1);read the text in the edit
    $ItText = _GUICtrlListView_GetItemTextString($dblv,-1);read the items in the row double clicked
;Item text could be spilt into its parts using stringsplit
    $text &= $ItText;add the items string to the text
    GUICtrlSetData($ed1,$text & @CRLF);write the text into the edit;
    
EndFunc ;==>Button_Click

Func next_button_clicked()
if $iStop < $iRows then 
$i_StartingRecord=$i_StartingRecord + $i_OffsetRecord
Build_ListViewItems()
EndIf
EndFunc

Func prev_button_clicked()
if $i_StartingRecord > 0 then   
$i_StartingRecord=$i_StartingRecord - $i_OffsetRecord
Build_ListViewItems()
EndIf
EndFunc


Func _createDBlistView($DB,$Query,$Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)
    $data=dbselect($Query)
    $headers=$tableField_Names
    $i_OffsetRecord = $Records_to_Display
        If $prev_Button Then 
            GUICtrlDelete($prev_Button)
            GUICtrlDelete($next_Button)
        EndIf
        GUICtrlCreateButton("<<Prev",$Listview_Left,$Listview_Top-30,50,25)
        GUICtrlSetOnEvent(-1, "prev_button_clicked")
        GUICtrlCreateButton("Next>>",$Listview_Left + 51,$Listview_Top-30,50,25)
        GUICtrlSetOnEvent(-1, "next_button_clicked")
        $pageing_label=GUICtrlCreateLabel("label",$Listview_Left+105,$Listview_Top-25,300,25)
        If $dblistview Then 
            _GUICtrlListView_DeleteAllItems ($dblistview)
            GUICtrlDelete($dblistview)
        EndIf
        $dblistview = GUICtrlCreateListView ($headers, $Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)
        Build_ListViewItems()
;       return $dblistview; This is what you have determine was needed
EndFunc

Func DB_Open()
    $conn=ObjCreate("ADODB.Connection")
    $conn.Provider="Microsoft.Jet.OLEDB.4.0"
    $conn.Open($DB)
    $conn.CursorLocation = 3
    Return $conn    
EndFunc

Func dbselect($query)
DB_Open()
$rs = ObjCreate("ADODB.recordset")
$rs.Open ($query, $conn)
$tableField_Names=""
For $tablefield in $rs.fields
    $tableField_Names &= $tablefield.name & "|"
next
$getRows_Data=$rs.GetRows()
$rs.close
DB_Close()
return $getRows_Data;=>_createDBlistView()
EndFunc

Func DB_Close()
    $conn.close()
EndFunc

Martin had graciously assited me earlier but I have been unable to get the script functioning. I would appreciated any advice offered... except giving up :D .

Thanks CC

Link to comment
Share on other sites

Currently you can't use _GUICtrlListView_DeleteAllItems with items created with GUICtrlCreateListViewItem

You'll need to do something like:

Func DeleteAllItems($dblistview)
    Local $ctrlID
    For $index = _GUICtrlListView_GetItemCount($dblistview) - 1 To 0 Step -1
        $ctrlID = _GUICtrlListView_GetItemParam($dblistview, $index)
        If $ctrlID Then GUICtrlDelete($ctrlID)
    Next
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Currently you can't use _GUICtrlListView_DeleteAllItems with items created with GUICtrlCreateListViewItem

You'll need to do something like:

Func DeleteAllItems($dblistview)
    Local $ctrlID
    For $index = _GUICtrlListView_GetItemCount($dblistview) - 1 To 0 Step -1
        $ctrlID = _GUICtrlListView_GetItemParam($dblistview, $index)
        If $ctrlID Then GUICtrlDelete($ctrlID)
    Next
EndFunc
It can be used just fine, you just need to pass the handle, not a control ID.

_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listview)).

"be smart, drink your wine"

Link to comment
Share on other sites

It can be used just fine, you just need to pass the handle, not a control ID.

_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listview)).

Until it starts deleting other controls on the form. The reason support at that time for id was taken out was deleting items on the form.

This method doesn't release the resources.

Add 4000 items, then delete them this way then try adding some more.

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

This method doesn't release the resources.

Add 4000 items, then delete them this way then try adding some more.

Ahah, I see. Thanks for clarification.

Have never noticed that, because if I plan to have a lot of LV items, I always use API adding (or virtualize the LV altogether).

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Ahah, I see. Thanks for clarification.

Have never noticed that, because if I plan to have a lot of LV items, I always use API adding (or virtualize the LV altogether).

What does "vitualize the LV" mean please?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks Siao, I tried searching the AutoIt forums and found nothing. I should have tried outside.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...