Google Sheet drop down

Hi All
i am very new to Anvil. I have a tiny bit of Python coding experience. So please take mercy on me. I am trying to populate a drop down with the first column of a google sheet. I have been able to figure out how to print the first column. But have not been able to figure out how to populate the list with the values. Any assistance would be greatly appreciated.

class Form1(Form1Template):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)
    db = app_files.lbdata
    ws = db["LBdata"]
    for r in db["LBdata"].rows:
       print(f"{r['Item Number']}")

Hi @jtsales and welcome to the forum!

You can find more information about DropDown menus and how to populate them here: Anvil Docs | Basic Components

If you want the items printed in the DropDown to be different than the selected value, then you can use a list of tuples of the form ("Option", value). For example, if you want the DropDown to list the Item Numbers, but select the entire row, you could do:

self.drop_down_1.items = [(row["Item Number"], row) for row in app_files.lbdata["LBdata"].rows]

I hope that helps!

2 Likes

Thanks Brooke. That is exactly what I was trying to do. Greatly appreciate the help. Can I ask if I want to store the rest of the values in the row. What should I be reading up about.