x001z Posted October 21, 2011 Share Posted October 21, 2011 Hi! I have a GUI with a empty listview what I need to do is to "reload" the list view with the new data. The data with I'm filling it, are from a DB query so the listview columns could be different, sometimes could be five cols sometimes could be ten, and so on... So this is my problem I have 2 tabs, in the first is the listview empty, for example if a do a query that return 2 cols, name and brand I need to display the data in the listview with the two columns with their names, an the data of each column, and if then I do a query that return 7 columns i want to display in the same listview the new 7 columns that could be different from the firs two, and if I do a query that return 5 col I need to reload the listview with the five columns. If a create a listview with two cols and then try to display the new data with more cols the listview only display the first two cols, or if I create a listview with ten cols and then I try to display a new query with five cols, the other five cols remain in the list view. In a few words, I want to adjust the listview with the exact number columns returned by the query and replace the old data with the new one and replace the column names. Thanks in advance! This is a plain example of what I need expandcollapse popup#Include <GuiListView.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Form1", 629, 447, 192, 124) $Tab1 = GUICtrlCreateTab(16, 24, 553, 409) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) $TabSheet1 = GUICtrlCreateTabItem("TabSheet1") $ListView1 = GUICtrlCreateListView("||", 48, 136, 441, 289) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Input1 = GUICtrlCreateInput("Input1", 48, 56, 121, 22) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Button1 = GUICtrlCreateButton("Button1", 180, 51, 75, 25, $WS_GROUP) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Button2 = GUICtrlCreateButton("Button2", 456, 95, 75, 25, $WS_GROUP) $TabSheet2 = GUICtrlCreateTabItem("TabSheet2") GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _button1() Case $Button2 _button2() EndSwitch WEnd Func _button1() _GUICtrlListView_DeleteAllItems($ListView1) ;~ Here Adjust Columns GUICtrlSetData($ListView1,"Col1|Col2") GUICtrlCreateListViewItem("l1c1|l1c2", $ListView1) EndFunc Func _button2() _GUICtrlListView_DeleteAllItems($ListView1) ;~ Here Adjust Columns GUICtrlSetData($ListView1,"NewCol1|NewCol2|NewCol3|NewCol4") GUICtrlCreateListViewItem("l1c1|l1c2|l1c3|l1c4", $ListView1) EndFunc Link to comment Share on other sites More sharing options...
jWalker Posted October 21, 2011 Share Posted October 21, 2011 I managed updating a listview like that: I had an array variable which holds all my things for my list: $listdata[$X] Than if i added something i used this lines: $listthings = "" For $X = 1 To $listdata[0] If $X == $listdata[0] Then $listthings = $listthings&$listdata[$X] Else $listthings = $listthings&"|"&$listdata[$X] EndIf Next If i wanted to delete sth from the list, i just searched it in the array and removed this part, then renewed the list... Link to comment Share on other sites More sharing options...
x001z Posted October 21, 2011 Author Share Posted October 21, 2011 Thanks jWalker, but there's any function to automatically adjust the number of columns? Link to comment Share on other sites More sharing options...
BrewManNH Posted October 22, 2011 Share Posted October 22, 2011 _GUICtrlListView_AddColumn and _GUICtrlListView_DeleteColumn would be the place to start. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Zedna Posted October 22, 2011 Share Posted October 22, 2011 As BrewManNH said + _GUICtrlListView_SetColumnWidth() Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
x001z Posted October 28, 2011 Author Share Posted October 28, 2011 Thanks for the responses. I do what you suggest but can I destroy the ListView and create a new one just in the same tab? because when i destroy the Listview an try to create another this listview is displayed on every tab. I think destroy and create a new one is faster than erase all data, delete columns and create the columns needed, or maybe is not the best way to do that... Link to comment Share on other sites More sharing options...
BrewManNH Posted October 28, 2011 Share Posted October 28, 2011 If you want to have the Listview in thr right tab you will need to use GUISwitch before creating the listview to switch to the proper tab. There are examples of what you need to do to accomplish this. Search for GUISwitch in this forum. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now