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

How can i populate a listbox in a selected combobox in vfp?

例如,组合框在 table1 中有类别数据,我想用子类别填充第二个 table 的列表框,其中类别 = 组合框。

好巧(?),我刚刚回答了一个类似的问题。此代码来自该答案,稍作修改以使用 Northwind 示例数据库的类别和产品(您的子类别)表:

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