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

时间:2018-09-03 14:02:54

标签: combobox listbox visual-foxpro foxpro

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

1 个答案:

答案 0 :(得分:1)

真是巧合(?),我刚刚回答了类似的问题。这段代码来自该答案,并进行了略微修改,以使用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