窗口上有text1(查询框) text2 text3,在text1里输入“女” 点击查询,那么text2显示李维娜 text3显示林敏红。版主版主Leftie给出的代码能够实现这个功能,但是如果查询符合的条件更多,那么text4  text5  tex6 怎么显示?
private sub command1_click()
    if trim(text1.text)="" then
        msgbox "请输入查询条件!",48,"提示"
        text1.setfocus
        exit sub
    end if
     
    text2.text=""
    text3.text=""
     
    with flexgrid
        for i=1 to .rows-1
            if trim(.textmatrix(i,3))=trim(text1.text) then
                if trim(text2.text)="" then
                    text2.text=.textmatrix(i,3)
                else
                    text3.text=.textmatrix(i,3)
            end if
        next i
    end with
end sub

解决方案 »

  1.   


    '先要说明,显示名字的文本框的Text2 . Text3 .Text4 采用数组方式。
    '以下文本框 Name = "TextName" Index = 0 到 5  (一共6个文本框,如果有多的自行增加) 
    private sub command1_click()
        if trim(text1.text)="" then
            msgbox "请输入查询条件!",48,"提示"
            text1.setfocus
            exit sub
        end if
        dim mIndex as long  
        mIndex=0
        
        with flexgrid
            for i=1 to .rows-1
                if trim(.textmatrix(i,3))=trim(text1.text) then
                    textName(mIndex).text=.textmatrix(i,3)      
                    mIndex=mIndex+1
                end if
            next i
        end with
    end sub
      

  2.   

    '先要说明,显示名字的文本框的Text2 . Text3 .Text4 采用数组方式。
    '以下文本框 Name = "TextName" Index = 0 到 5  (一共6个文本框,如果有多的自行增加) 
    '就是采用比较的方式。找到了要的数据,将数据放入相应(mindex)的Text中。再 mindex+1,
    '下次找到的数据放入下一个文本框
    private sub command1_click()
        if trim(text1.text)="" then
            msgbox "请输入查询条件!",48,"提示"
            text1.setfocus
            exit sub
        end if
        dim mIndex as long  
        mIndex=0
        
        with flexgrid
            for i=1 to .rows-1
                if trim(.textmatrix(i,3))=trim(text1.text) then
                    textName(mIndex).text=.textmatrix(i,1) ‘这里应该是(i,1)吧,上面是复制的代码.     
                    mIndex=mIndex+1
                end if
            next i
        end with
    end sub
      

  3.   

    用筛选的方式,可以把查询结果显示到另外一个msflexgrid2控件上去
    我一般用DATAGRID控件或VSFLEXGRID,这些控件可以直接修改数据,也可以排序,用RS.FIRTER="性别='女'"就可以筛选出来了,要显示原来所有数据,只要rs.filter=""就行了