Mar-10-2022, 09:14 PM
I'm trying to use a checkbox treeview to display the results of an SQLite query. I build the query's SELECT, JOIN and WHERE clauses on the fly based on user inputs as to which columns to display and what restrictions (the where) they want to apply. I have a series of checkboxes and I get whether a checkbox is selected or not. Then I use that to add to the text variables that are pieces of the eventual query. To make sure that I can always have a known select item at the beginning my start includes the primary key from the table I am doing the select from. I have one problem with how I build my query when I have an item I am searching for. I can create it using string operations but that isn't a secuew way to build the query to prevent SQL injection. That is a different problem from the treeview display though. I'll go post about the SQLite issue elsewhere.
I am having 2 problems with the treeview.
1. I can't figure out how to dynamically set up the number of columns when I create the treeview
2. I can't figure out how to start filling the treeview rows at item[1] in my cursor not item[0]
This is the create statement but it always creates all the columns I want to somehow only put the number I really need. I know how many columns I actually want to display. Column zero is used for the checkbox for each row.
I am having 2 problems with the treeview.
1. I can't figure out how to dynamically set up the number of columns when I create the treeview
2. I can't figure out how to start filling the treeview rows at item[1] in my cursor not item[0]
This is the create statement but it always creates all the columns I want to somehow only put the number I really need. I know how many columns I actually want to display. Column zero is used for the checkbox for each row.
CheckboxTreeview(self.bottomdisplay.scrollable_frame,column=('column0', 'column1', 'column2', 'column3', 'column4', 'column5' , 'column6', 'column7', 'column8', 'column9'), show=('headings','tree'),selectmode='extended') checkboxheaders = self.get_column_headers() contact_search_tree.column('#0', minwidth=35, width=35)I name the columns according to what they will contain
for i,name in enumerate(checkboxheaders): print(i) contact_search_tree.heading('#' + str(i+1), text=name) contact_search_tree.column('#'+ str(i+1),minwidth=1)I execute my query the query problem comes in when I have cmd variables but I can get a proper query by not making a where clause and so I get all the data in the table. Figures i'd deal with one problem at a time. When I fill in the row in the if row in results step I get item [0} under my column 1 and so on.
if cmdvariables: resultcursor.execute(cmd, cmdvariables) else: resultcursor.execute(cmd) results = resultcursor.fetchall() for row in results: # todo need to figure out how to start the values at item 1 in the row not item zero contact_search_tree.insert('', 'end', values=row) print(row) contact_search_tree.config(height=len(results)) contact_search_tree.pack()Any assistance is appreciated.