Jump to content

How i do txt search in listbox?


Go to solution Solved by Melba23,

Recommended Posts

Hi friends, i creat one gui and button,  add and remowe ok,

but, I want to find it in the list when I write the word entry, how i do ?

#include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    $Form1_1 = GUICreate("  .:|:. Müşteri Kayıt .:|:.", 406, 335, 238, 159)
    GUISetBkColor(0x9DB9EB)
    $Group1 = GUICtrlCreateGroup("Kayıt", 8, 8, 294, 65)
    $Input1 = GUICtrlCreateInput("", 92, 30, 195, 21)
    $Label1 = GUICtrlCreateLabel("Adı ve Soyadı:", 16, 32, 72, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group2 = GUICtrlCreateGroup("", 312, 8, 81, 65)
    $Button1 = GUICtrlCreateButton("Ekle", 325, 25, 55, 17)
    $Button2 = GUICtrlCreateButton("Sil", 325, 45, 55, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Items = GUICtrlCreateList("", 8, 88, 297, 240)
    $Dosya = @AppDataDir & "\kisiler.ini"
    GuiCtrlSetData(-1, IniRead($Dosya, "kullanıcılar", "adlar", ""))
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

Func _ReadItems()
    Local $iCnt = _GUICtrlListBox_GetCount($Items)
    Local $sMsg = ""
    For $n = 0 To $iCnt - 1
    $sMsg &= _GUICtrlListBox_GetText($Items, $n) & "|"
    Next
    Return $sMsg
EndFunc

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

Case $Button1 ;ekle
    $Dosya = $Dosya
    If Not StringInStr(IniRead($Dosya, "kullanıcılar", "adlar", "") & "|", GUICtrlRead($Input1)) Then
    IniWrite($Dosya, "kullanıcılar", "adlar", _ReadItems() & GUICtrlRead($Input1))
    EndIf

    GuiCtrlSetData($Items, "")
    GuiCtrlSetData($Items, IniRead($Dosya, "kullanıcılar", "adlar", ""))

Case $Button2 ;sil
    $Dosya = $Dosya
    Global $MusteriData = StringStripWS(IniRead($Dosya,"Kullanıcılar","Adlar",""), 3)

    $Gread = StringStripWS(GUICtrlRead($Items), 3)
            If $Gread <> "" And StringInStr("|" & $MusteriData & "|", "|" & $Gread & "|") <> 0 Then
                $MusteriData = StringReplace($MusteriData, $Gread, "")
                $MusteriData = StringReplace($MusteriData, "||", "|")
                If $MusteriData = StringRight($MusteriData,1) = "|" Then $MusteriData = StringTrimRight($MusteriData,1)

                GUICtrlSetData($Items, "")
                GUICtrlSetData($Items, $MusteriData)

                IniWrite($Dosya,"Kullanıcılar","Adlar",$MusteriData)
            EndIf



    EndSwitch
    WEnd
Link to comment
Share on other sites

  • Moderators

AdemSezgin,

Have you looked at the Help file before posting? I think not or _GUICtrlListBox_FindString might have struck you as a possible solution. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

exp script this, i want this,,,

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>


$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

Global $Input1

_Main()

Func _Main()
    Local $Form1_1

    ; Create GUI
    $Form1_1 = GUICreate("(UDF) ComboBox Create", 400, 296)
    $Input1 = _GUICtrlComboBox_Create($Form1_1, "", 2, 2, 396, 296)

    $Button1 = GUICtrlCreateButton("Ekle", 325, 100, 55, 17)
    $Button2 = GUICtrlCreateButton("Sil", 325, 124, 55, 17)

    Global $list = GUICtrlCreateList("", 2, 25, 296, 240)
        GuiCtrlSetData(-1, IniRead(@AppDataDir & "\kisiler.ini", "kullanıcılar", "adlar", ""))

    Global $Items = "murat ak", $Items_S = StringSplit($Items, "|")

    GUICtrlSetData(-1, $Items)
    Global $check = GUICtrlCreateCheckbox("gelişmiş arama", 2, 270, 200, 21)
    GUISetState()



    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $Input1
            Switch $iCode

                Case $CBN_EDITCHANGE ; Sent when the edit control portion of a combo box is about to display altered text
                    Local $text = _GUICtrlComboBox_GetEditText($Input1)
                    If BitAND(GUICtrlRead($check), $GUI_CHECKED) = 0 Then Return _GUICtrlListBox_SelectString($list, $text)
                    _GUICtrlListBox_FindInText($list, $text)

                    Local $count = _GUICtrlListBox_GetCount($list)
                    If $text = "" Then

                        For $i = 1 To $Items_S[0]

                            _GUICtrlListBox_AddString($list, $Items_S[$i])

                        Next
                    Else

                        For $i = 1 To $Items_S[0]
                            If StringInStr($Items_S[$i], $text) Then
                                _GUICtrlListBox_ResetContent($list)
                                _GUICtrlListBox_AddString($list, $Items_S[$i])
                                Return
                            EndIf
                        Next
                    EndIf


            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
Link to comment
Share on other sites

  • Moderators
  • Solution

AdemSezgin,

I would do it like this: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Test", 200, 400)

$cInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$cList = GUICtrlCreateList("", 5, 30, 190, 365) ;, BitOR(0x00100000, 0x00200000))
$cCheck_Dummy = GUICtrlCreateDummy()

GUISetState()

_Fill_List()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cList
            $sChosen = GUICtrlRead($cList)
            If $sChosen <> "" Then
                GUICtrlSetData($cInput, $sChosen)
            EndIf
        Case $cCheck_Dummy
            $sText = GUICtrlRead($cInput)
            $iIndex = _GUICtrlListBox_FindString($cList, $sText)
            If $iIndex <> -1 Then
                _GUICtrlListBox_SetCurSel($cList, $iIndex)
            Else
                _GUICtrlListBox_SetCurSel($cList, -1)
            EndIf
    EndSwitch

WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    If $lParam = GUICtrlGetHandle($cInput) Then
        If BitShift($wParam, 16) = $EN_CHANGE Then
            GUICtrlSendToDummy($cCheck_Dummy)
        EndIf
    EndIf

EndFunc

Func _Fill_List()

    Local $sData
    For $i = 0 To 99
        $sData &= Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & "|"
    Next
    GUICtrlSetData($cList, $sData)

EndFunc
All clear? :)

 

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

AdemSezgin,

You add the necessary bits of my script (the creation of the dummy, the GUIRegisterMsg line, the Case code for the list and the dummy, and the handler function) to your script and change the variable names to match yours. When I do that it works perfectly. :)

Give it a try and come back if you cannot get it to work - but I want to see the code you tried if so. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Thank you :) i finish gui :))

#include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    $Form1_1 = GUICreate("  .:|:. Müşteri Kayıt .:|:.", 406, 335, 238, 159)
    GUISetBkColor(0x9DB9EB)
    $Group1 = GUICtrlCreateGroup("Kayıt", 8, 8, 294, 65)
    $cInput = GUICtrlCreateInput("", 92, 30, 195, 21)
    $Label1 = GUICtrlCreateLabel("Adı ve Soyadı:", 16, 32, 72, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group2 = GUICtrlCreateGroup("", 312, 8, 81, 65)
    $Button1 = GUICtrlCreateButton("Ekle", 325, 25, 55, 17)
    $Button2 = GUICtrlCreateButton("Sil", 325, 45, 55, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)

    $cList = GUICtrlCreateList("", 8, 88, 297, 240) ;liste kutusu olusturuyoruz------
    $Dosya = @AppDataDir & "\kisiler.ini"
    GuiCtrlSetData(-1, IniRead($Dosya, "kullanıcılar", "adlar", ""));----------------

    GUISetState(@SW_SHOW)
    $cCheck_Dummy = GUICtrlCreateDummy() ; eklenecek-----------

;~ _Fill_List()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ;eklenecek -------------

    #EndRegion ### END Koda GUI section ###

Func _ReadcList() ;bu eklenecek-------------------------------------------
    Local $iCnt = _GUICtrlListBox_GetCount($cList)
    Local $sMsg = ""
    For $n = 0 To $iCnt - 1
    $sMsg &= _GUICtrlListBox_GetText($cList, $n) & "|"
    Next
    Return $sMsg
EndFunc



    While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cList;-------------------------------- eklenecek-----------
            $sChosen = GUICtrlRead($cList)
            If $sChosen <> "" Then
                GUICtrlSetData($cInput, $sChosen)
            EndIf
        Case $cCheck_Dummy
            $sText = GUICtrlRead($cInput)
            $iIndex = _GUICtrlListBox_FindString($cList, $sText)
            If $iIndex <> -1 Then
                _GUICtrlListBox_SetCurSel($cList, $iIndex)
            Else
                _GUICtrlListBox_SetCurSel($cList, -1)
            EndIf; eklenecek -------------------------------------------

Case $Button1 ;ekle butonu icin görevvvvvv--------------
    $Dosya = $Dosya
    If Not StringInStr(IniRead($Dosya, "kullanıcılar", "adlar", "") & "|", GUICtrlRead($cInput)) Then
    IniWrite($Dosya, "kullanıcılar", "adlar", _ReadcList() & GUICtrlRead($cInput))
    EndIf

    GuiCtrlSetData($cList, "")
    GuiCtrlSetData($cList, IniRead($Dosya, "kullanıcılar", "adlar", ""))

Case $Button2 ;sil butonu icin görev ---------------------
    $Dosya = $Dosya
    Global $MusteriData = StringStripWS(IniRead($Dosya,"Kullanıcılar","Adlar",""), 3)

    $Gread = StringStripWS(GUICtrlRead($cList), 3)
            If $Gread <> "" And StringInStr("|" & $MusteriData & "|", "|" & $Gread & "|") <> 0 Then
                $MusteriData = StringReplace($MusteriData, $Gread, "")
                $MusteriData = StringReplace($MusteriData, "||", "|")
                If $MusteriData = StringRight($MusteriData,1) = "|" Then $MusteriData = StringTrimRight($MusteriData,1)

                GUICtrlSetData($cList, "")
                GUICtrlSetData($cList, $MusteriData)

                IniWrite($Dosya,"Kullanıcılar","Adlar",$MusteriData)
            EndIf



    EndSwitch
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) ;bu da eklenecekk -----------------------

    If $lParam = GUICtrlGetHandle($cInput) Then
        If BitShift($wParam, 16) = $EN_CHANGE Then
            GUICtrlSendToDummy($cCheck_Dummy)
        EndIf
    EndIf

EndFunc

;~ Func _Fill_List()

;~     Local $sData
;~     For $i = 0 To 99
;~         $sData &= Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & "|"
;~     Next
;~     GUICtrlSetData($cList, $sData)

;~ EndFunc
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...