frb_noname
Junior Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Есть элемент Listview и несколько элементов Input, значения которых соответствуют значениям определенных колонок списка. Как сделать, чтобы при смене активной строки списка (хоть кликом мышки хоть клавиатурой) изменялось значение соответствующих инпутов ? Как это сделать например в следующем коде (для запуска нужен sqlite3.dll ) : Код: #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <sqlite.au3> #include <guilistview.au3> #include <GuiConstants.au3> $Form1_1 = GUICreate("Справочник телефонов", 679, 365, 135, 114) $Group1 = GUICtrlCreateGroup("Поиск в базе", 2, 4, 334, 326) $List = GUICtrlCreateListView("Код|Абонент|Номер", 8, 66, 321, 253) _GUICtrlListView_SetColumnWidth($list,0,0) _GUICtrlListView_SetColumnWidth($list,1,217) _GUICtrlListView_SetColumnWidth($list,2,100) $context = GUICtrlCreateContextMenu($list) $context1 = GUICtrlCreateMenuItem("Удалить",$list) $for_search = GUICtrlCreateInput("", 8, 20, 201, 24) $But_search = GUICtrlCreateButton("Поиск !", 213, 20, 65, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $But_all = GUICtrlCreateButton("Все", 284, 20, 43, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label4 = GUICtrlCreateLabel("Результаты поиска :", 11, 50, 109, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Просмотр и правка", 339, 4, 333, 326) $Input_abon = GUICtrlCreateInput("", 347, 66, 214, 24) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Edit_descr = GUICtrlCreateEdit("", 346, 152, 321, 170) $Label1 = GUICtrlCreateLabel("Абонент :", 348, 50, 52, 13) $Label2 = GUICtrlCreateLabel("Дополнительно :", 347, 138, 90, 12) $Label3 = GUICtrlCreateLabel("Номер :", 348, 95, 44, 14) $Input_phone = GUICtrlCreateInput("", 347, 109, 153, 24) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $But_edit = GUICtrlCreateButton("Править", 580, 20, 83, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $But_new = GUICtrlCreateButton("Новый абонент", 348, 20, 127, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $But_add = GUICtrlCreateButton("Сохранить", 482, 20, 91, 25) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) #EndRegion ### END Koda GUI section ### GUISetState(@SW_SHOW) Dim $tbl="baza", $base="phone_base.db", $rez, $rows, $columns if not FileExists(@ScriptDir & "\" & $base) Then run_sqlite() make_structure() stop_sqlite() Else EndIf run_sqlite() select_all() stop_sqlite() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $But_new GUICtrlSetData($Input_abon,"","") GUICtrlSetData($Input_phone,"","") GUICtrlSetData($Edit_descr,"","") Case $But_add run_sqlite() ;MsgBox(0,"","insert into baza '" & GUICtrlRead($Input_abon) & "','" & GUICtrlRead($Input_phone) & "','" & GUICtrlRead($Edit_descr) & "';")) If Not _SQLite_Exec (-1, "insert into baza values (null,'" & GUICtrlRead($Input_abon) & "','" & GUICtrlRead($Input_phone) & "','" & GUICtrlRead($Edit_descr) & "');") = $SQLITE_OK Then _ MsgBox(16, "SQLite Error", _SQLite_ErrMsg ()) _SQLite_Exec (-1, "commit;") select_all() stop_sqlite() Case $But_all run_sqlite() select_all() stop_sqlite() Case $context1 run_sqlite() delfrombaza() stop_sqlite() EndSwitch WEnd Func run_sqlite() ;===== _SQLite_Startup () ;===== If @error > 0 Then ;===== MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!") ;===== Exit - 1 ;===== EndIf ;===== _SQLite_Open ($base) ;===== If @error > 0 Then ;===== MsgBox(16, "SQLite Error", "Can't Load Database!") ;===== Exit - 1 ;===== EndIf ;===== EndFunc ;==========================>>> Run_Sqlitr =================;===== Func make_structure() If Not _SQLite_Exec (-1, "CREATE TABLE if not exists [" & $tbl & "] (" _ & "[kod] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," _ & "[abon] VARCHAR(255) UNIQUE not NULL," _ & "[nomer] VARCHAR(255) not null," _ & "[descript] VARCHAR(500) null);") = $SQLITE_OK Then _ MsgBox(16, "SQLite Error", _SQLite_ErrMsg ()) EndFunc ;============================>>> make_structure ========================== ;===================================== stop_sqlite =====================;===== Func stop_sqlite() ;===== _SQLite_Close() ;===== _SQLite_Shutdown() ;===== EndFunc ;==========================>>> stop_Sqlite =====================;===== Func select_all() ;================================= ВСЕ ======================================== _GUICtrlListView_DeleteAllItems($list) $tbl_rez = _SQLite_GetTable2d (-1, "SELECT kod, abon, nomer FROM baza order by abon;", $rez, $rows, $columns) If $tbl_rez = $SQLITE_OK Then _SQLite_Display2DResult($rez) ;|=========== занесение данных двухмерного массива в список формы ================================= For $x=1 To $rows GUICtrlCreateListViewItem($rez[$x][0] & "|" & $rez[$x][1] & "|" & $rez[$x][2], $list) Next ;|=========================================================================================== Else MsgBox(16, "SQLite Error: " & $tbl_rez, _SQLite_ErrMsg ()) EndIf EndFunc Func delfrombaza() if MsgBox(4,"","Действительно удалить запись ?")=6 Then ;====================== получение уникального кода записи из активной строки списка ==================== $kodrecno=guictrlread(GUICtrlRead($list)) $kodrecno=Stringleft($kodrecno,stringInStr($kodrecno,"|",2,1)-1) ;============ удаление файла из базы по уникальному номеру записи ================================ If Not _SQLite_Exec (-1, "delete from baza where kod=" & $kodrecno & ";") = $SQLITE_OK Then _ MsgBox(16, "SQLite Error", _SQLite_ErrMsg ()) select_all() Else EndIf EndFunc ;==============>>>>>> openfile() |
|