一个list文本框,
我怎么样才能一次把里面所有字段全部选择,而且在另外的程序中查询这些字段呢!

解决方案 »

  1.   

    快速选择全部项目 
    我们在使用 List 控件时,经常需要全部选择其中的项目,在项目较少时,我们可以逐项设置 Selected 来选择全部的项目,但当项目较多时,这样做就比较费时,其实,我们可以用 API 函数来简单实现此功能: 
    Dim nRet As Long 
    Dim bState as Boolean 
    bState=True 
    nRet = SendMessage(lstList.hWnd, LB_SETSEL, bState, -1) 
    函数声明: 
    Public Declare Function SendMessage Lib "User32" Alias "SendMessageA" ( ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Const WM_USER = &H400
    Public Const LB_SETSEL = (WM_USER + 6)
      

  2.   

    假设我做一个循环的话,
    for i =1 to list.listcount-1
      txt(i)= list(i)
      next i 
      那么你的 select语句又该怎么写?
      

  3.   

    to cso(sjxsoft-天水是我家) :
    你的代码测试了吗?我测试的结果是无效(环境win2000,vb6 sp6)
      

  4.   

    下面是我的代码(实现全选的):
    Option Explicit
    Private Const LB_GETCOUNT = &H18B
    Private Const LB_SELITEMRANGE = &H19B
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lparam As Long) As Long
    Private Sub Command1_Click()
        Dim lparam As Long '高字和低字分别为选择(或撤消选择)的第一和最后一个条目的索引
        Dim i As Long
        i = SendMessage(List1.hwnd, LB_GETCOUNT, 0&, 0&) '获得listbox中的条目数量
        lparam = (i - 1) * 2 ^ 16 + 0 '改成这样也行:lparam = 0 * 2 ^ 16 + i-1,即lparam=i-1
        SendMessage List1.hwnd, LB_SELITEMRANGE, True, lparam&
    End SubPrivate Sub Form_Load()
        Dim i As Long
        For i = 1 To 100
            List1.AddItem "line " + CStr(i)
        Next
    End Sub
      

  5.   

    to 楼主:
    我怎么没看出来listbox和select语句有什么必然的联系,下面是我假设的,你看是不是这个意思:在listbox中存储着一个表的所有字段名,你想通过对listbox进行选择,动态生成你的select语句,是这样吗?
      

  6.   

    dim txtstr as string
    dim selsem as string 
    txtstr = list(1)
    for i =2 to list.listcount-1
      txtstr = txtstr & "," & list(i)
      next i 
    selsem = "select " & txtstr & " from xxxx where ...."
      

  7.   

    这个是http://vbnet.mvps.org/index.html?code/listapi/clearlistitems.htm的,应该没有错,但是我的不成功
      

  8.   

    to rainstormmaster(暴风雨 v2.0) 
    你的代码我试过了也不成功(xp[SP2] + VB6[SP6])
      

  9.   

    在设计介段把list1的MultiSelect设成1然后
        Dim i As Integer
        List1.MultiSelect = True
        
        For i = 0 To List1.ListCount - 1
            List1.Selected(i) = True
            
        Next