Jump to content
Sign in to follow this  
ShadowElf

multiple forms problem

Recommended Posts

ShadowElf

The problem: I have a form... From menu I start another form.... who have a list and a a button to delete items from it.

I can't delete items from list. I used a GUISwitch($Formuseri1) to "focus" events on form 2 but it not ok.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <MySQL.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 680, 236, 95, 129)
$MenuItem4 = GUICtrlCreateMenu("Optiuni")

$MenuItem28 = GUICtrlCreateMenuItem("Utilizatori", $MenuItem4)
GUICtrlSetOnEvent(-1, "useri")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
sleep (100)
WEnd

Func useri()
Global $formuseri1, $Listauseri
Local $button1, $button2, $button3, $button4, $resursauseri, $x=1, $y=1
if $Formuseri1 Then
        GUIDelete($Formuseri1)
        EndIf
$Formuseri1 = GUICreate("Utilizatori sistem", 526, 269, 211, 113)
$Listauseri = GUICtrlCreateListView("", 14, 24, 495, 175)
    _GUICtrlListView_AddColumn($Listauseri, "ID", 50)
    _GUICtrlListView_AddColumn($Listauseri, "Nume", 100)
    _GUICtrlListView_AddColumn($Listauseri, "Prenume", 100)
    _GUICtrlListView_AddColumn($Listauseri, "Titlu", 100)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    dbconnect()
    $resursauseri=_Query($dbconnect, "SELECT TITLE, FNAME, LNAME from users ORDER BY FNAME")
    With $resursauseri
    While Not .EOF
        _GUICtrlListView_AddItem($Listauseri, $x)
        _GUICtrlListView_AddSubItem($Listauseri,$x-1,.Fields ("FNAME").value,$y)
        _GUICtrlListView_AddSubItem($Listauseri,$x-1,.Fields ("LNAME").value,$y+1)
        _GUICtrlListView_AddSubItem($Listauseri,$x-1,.Fields ("TITLE").value,$y+2)
        $x=$x+1
    .MoveNext
    WEnd
    EndWith
$Button2 = GUICtrlCreateButton("Sterge", 140, 208, 121, 41)
GUICtrlSetOnEvent(-1, "deluseri")
$Button4 = GUICtrlCreateButton("Renunta", 390, 209, 121, 41)
GUICtrlSetOnEvent(-1, "outuseri")
GUISwitch($Formuseri1)
GUISetState(@SW_SHOW)
EndFunc


Func deluseri()
    Global $Listauseri
    Local $user[3], $ccc
    $ccc=_GUICtrlListView_GetSelectedIndices($listauseri)
    _GUICtrlListView_DeleteItem($listauseri, number($ccc))
    MsgBox(-1, "cc", _GUICtrlListView_GetSelectedIndices($listauseri))
    $User[0]=_GUICtrlListView_GetItemText($listauseri, _GUICtrlListView_GetSelectedIndices($Listauseri), 1)
    $User[1]=_GUICtrlListView_GetItemText($listauseri, _GUICtrlListView_GetSelectedIndices($Listauseri), 2)
    $User[2]=_GUICtrlListView_GetItemText($listauseri, _GUICtrlListView_GetSelectedIndices($Listauseri), 3)
    dbconnect()
    _Query($dbconnect, "DELETE FROM users WHERE FNAME='"&$user[0]&"' AND LNAME='"&$user[1]&"' AND TITLE='"&$user[2]&"'")
    _MySQLEnd($dbconnect)
EndFunc

I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

Share this post


Link to post
Share on other sites
Valuater

Maybe you could try this...

If $formuseri1 Then

;GUIDelete($formuseri1)

GUICtrlDelete($Listauseri )

EndIf

to delete the control rather than the GUI. at times I have found that once I delete a GUI this way, I cannot re-connect with the controls.

This is an effort for you to try, not an absolute answer. Also be sure to remove the GUISWitch.

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Melba23

ShadowElf,

I found that you appear to need the handle of the LV (via GUICtrlGetHandle) in the _GUICtrlListView_DeleteItem function to delete a line. This heavily modded extract from your code works for me:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode", 1)

Global $formuseri1, $Listauseri

Local $button1, $button2, $button3, $button4, $resursauseri, $x = 1, $y = 1
If $formuseri1 Then
    GUIDelete($formuseri1)
EndIf
$formuseri1 = GUICreate("Utilizatori sistem", 526, 269, 211, 113)
$Listauseri = GUICtrlCreateListView("", 14, 24, 495, 175)
_GUICtrlListView_AddColumn($Listauseri, "ID", 50)
_GUICtrlListView_AddColumn($Listauseri, "Nume", 100)
_GUICtrlListView_AddColumn($Listauseri, "Prenume", 100)
_GUICtrlListView_AddColumn($Listauseri, "Titlu", 100)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
For $x = 0 To 3
    _GUICtrlListView_AddItem($Listauseri, $x)
    _GUICtrlListView_AddSubItem($Listauseri, $x, $x, $y)
    _GUICtrlListView_AddSubItem($Listauseri, $x, $x, $y + 1)
    _GUICtrlListView_AddSubItem($Listauseri, $x, $x, $y + 2)
Next
$button2 = GUICtrlCreateButton("Sterge", 140, 208, 121, 41)
GUICtrlSetOnEvent(-1, "deluseri")
$button4 = GUICtrlCreateButton("Renunta", 390, 209, 121, 41)
GUICtrlSetOnEvent(-1, "On_Exit")
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Func deluseri()
    Local $ccc = _GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($Listauseri), True)

    For $i = 1 To $ccc[0]
        _GUICtrlListView_DeleteItem(GUICtrlGetHandle($Listauseri), $ccc[$i])
    Next

EndFunc   ;==>deluseri

In future, please note you are likely to get help quicker if you post code that does not require a great deal of fiddling just to get it to run - for example, we do not have your database file, so we cannot load it and have to rewrite the code to get a filled LV. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
ShadowElf

thx melba23. it works

I will post code in a smart version from now on

I allready cut a lot of my code, I miss database connect

but why

_GUICtrlListView_DeleteItem($list1, _GUICtrlListView_GetSelectedIndices($list1)) works when I have only a form, and

_GUICtrlListView_DeleteItem(GUICtrlGetHandle($listauseri), _GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($Listauseri)))

when I have more forms opened

??


I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

Share this post


Link to post
Share on other sites
Melba23

ShadowElf,

All of the GUICtrl* functions (the ones in the UDFs rather than the built-in versions) use HANDLEs rather than ControlIDs. Just to be clear:

- a HANDLE is an internal Windows ID for any window or control - it looks like this: 0x0004563

- a ControlID is an internal AutoIt ID for controls created within a GUI - it looks like this: 23

However, a GUI created with GUICreate returns a HANDLE and not a ControlID.

Whenever I use the UDF functions, and I have created the control with the built-in create function, I always do something this:

$cLV = GUICtrlCreateListview(......)
$hLV = GUICtrlGetHandle($cLV)

Now I have 2 easily differentiated variables ready for use in either built-in or UDF functions. ;)

Look at this script and see what is returned by the various functions:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)
ConsoleWrite("This is the HANDLE of the GUI window: " & $hGUI & @CRLF)

$cButton = GUICtrlCreateButton("", 10, 10, 80, 30)
ConsoleWrite("This is the ControlID of the button: " & $cButton & @CRLF)
$hButton = GUICtrlGetHandle($cButton)
ConsoleWrite("This is the HANDLE of the button: " & $hButton & @CRLF)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I hope that is clear. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
ShadowElf

thx a lot, I understand


I like IT: php, mysql, codeingiter, css, jquery and AUTOIT

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.