如何在vfp中的选定组合框中填充列表框?

问题描述 投票:0回答:1

例如,组合框具有table1中类别的数据,我想从第二个表填充列表框,其中子类别为categories = combobox。

combobox listbox visual-foxpro foxpro
1个回答
1
投票

多么巧合(?),我刚刚回答了类似的问题。此代码来自该答案,略微修改以使用Northwind示例数据库的Categories和Products(子类别)表:

Public oForm
oForm = Createobject('SampleForm')
oForm.Show()


Define Class SampleForm As Form
    Height = 800
    Width=600
    DataSession = 2
    Add Object cmbCategories As ComboBox With Top=10, Left=10, Width=250
    Add Object lstProducts As ListBox With Top=10, Left=280, Height=780, Width=310

    Procedure Init
        With This.cmbCategories
            .RowSourceType = 3 && -SQL
            .RowSource = "select CategoryName, CategoryId from ('"+;
                _Samples+;
                "Northwind\Categories') into cursor crsCategories nofilter"
            .ListIndex=1
        Endwith
        With This.lstProducts
            .RowSourceType = 3 && -SQL
            .RowSource = "select ProductName, ProductId from ('"+;
                _Samples+;
                "Northwind\Products') p"+;
                " where p.CategoryId = crsCategories.CategoryId"+;
                " into cursor crsProducts nofilter"
        Endwith
    Endproc

    Procedure cmbCategories.InteractiveChange
        With Thisform.lstProducts
            .ListIndex = 0
            .Requery()
        Endwith
    Endproc
Enddefine
© www.soinside.com 2019 - 2024. All rights reserved.