各位帮个忙,现在有个要利用ListView控件+ImageList绑定数据库显示数据
下面是数据库中的2个表:监控温度表和Roomtemp表
监控温度表
         id       温度      湿度         时间
6 21.4 40.62 2007-1-17 10:13:07
8 21.36 40.89 2007-1-17 10:14:01
3 21.69 39.91 2007-1-17 10:16:13
10 21.62 39.81 2007-1-17 10:16:33
2 20.57 43.52 2007-1-17 10:10:10
15 20.63 41.35 2007-1-17 10:18:51
5 22.53 38.85 2007-1-17 10:10:10
2 21.25 41.34 2007-1-17 10:22:18
6 21.89 39.90 2007-1-17 10:22:41
12 21.89 39.9 2007-1-17 10:22:44
2 22.96 35.3 2007-1-17 10:25:02
12 22.08 35.71 2007-1-17 10:25:34
20 22.08 35.71 2007-1-17 10:25:43
5 21.54 37.57 2007-1-17 10:27:23
1 22.25 37.47 2007-1-17 10:27:25
Roomtemp表
          记录号      id         楼层     状态
34     1      1       空闲
35     2      1     空闲
36     3      1     空闲
37     4      1     空闲
38     5      1     空闲
39     6      1     空闲
40        7      1     空闲
41     8      1     空闲
42     9      1     空闲
43    10      1     空闲
比如说Roomtemp表中id=1时,ListView1.ToolTipText显示的温度位21.4 
下面是软件界面的连接 和 代码
界面:
 http://qian21h.bokee.com/photo/view.fcgi?id=7100580&mode=3
代码:
 Private Sub Comfind_Click()
On Error Resume Next
Dim q As IntegerIf Check1.Value Then
   If Text1.Text = 0 Or Text1.Text = "" Then
    MsgBox "请输入间隔时间"
    Exit Sub
   End If
  SQLStr = "Select distinct 时间, * From 监控温度表,roomtemp Where 监控温度表.时间 between '" + Str(dtStart.Value) + "'AND '" + Str(dtEnd.Value) + "'  And DateDiff(" + "mi" + ",'" + Str(dtStart.Value) + "',时间) % " + Str(Text1.Text) + "=0 and (监控温度表.id=roomtemp.id) order by 时间 asc "
Else
  SQLStr = "select * from 监控温度表,roomtemp  where (监控温度表.时间 between '" + Str(dtStart.Value) + "'AND '" + Str(dtEnd.Value) + "') and (监控温度表.id=roomtemp.id) order by 时间 asc"
End If
Set rs = ESQL(SQLStr)
For q = 1 To rs.RecordCount
 ListView1.ToolTipText = "温度:" & rs!温度 & "℃ " //我这样做都是显示相同数据了
rs.MoveNext
Next
End Sub

解决方案 »

  1.   

    VB中给listview的item添加多行气泡式Tooltip:
    一个类模块,命名为:CTooltip,代码如下:Option ExplicitPrivate Declare Sub InitCommonControls Lib "comctl32.dll" ()''Windows API Functions
    Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long''Windows API Constants
    Private Const WM_USER = &H400
    Private Const CW_USEDEFAULT = &H80000000''Windows API Types
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type''Tooltip Window Constants
    Private Const TTS_NOPREFIX = &H2
    Private Const TTF_TRANSPARENT = &H100
    Private Const TTF_CENTERTIP = &H2
    Private Const TTM_ADDTOOLA = (WM_USER + 4)
    Private Const TTM_ACTIVATE = WM_USER + 1
    Private Const TTM_UPDATETIPTEXTA = (WM_USER + 12)
    Private Const TTM_SETMAXTIPWIDTH = (WM_USER + 24)
    Private Const TTM_SETTIPBKCOLOR = (WM_USER + 19)
    Private Const TTM_SETTIPTEXTCOLOR = (WM_USER + 20)
    Private Const TTM_SETTITLE = (WM_USER + 32)
    Private Const TTS_BALLOON = &H40
    Private Const TTS_ALWAYSTIP = &H1
    Private Const TTF_SUBCLASS = &H10
    Private Const TTF_IDISHWND = &H1
    Private Const TTM_SETDELAYTIME = (WM_USER + 3)
    Private Const TTDT_AUTOPOP = 2
    Private Const TTDT_INITIAL = 3Private Const TOOLTIPS_CLASSA = "tooltips_class32"''Tooltip Window Types
    Private Type TOOLINFO
        lSize As Long
        lFlags As Long
        hwnd As Long
        lId As Long
        lpRect As RECT
        hInstance As Long
        lpStr As String
        lParam As Long
    End Type
    Public Enum ttIconType
        TTNoIcon = 0
        TTIconInfo = 1
        TTIconWarning = 2
        TTIconError = 3
    End EnumPublic Enum ttStyleEnum
        TTStandard
        TTBalloon
    End Enum'local variable(s) to hold property value(s)
    Private mvarBackColor As Long
    Private mvarTitle As String
    Private mvarForeColor As Long
    Private mvarIcon As ttIconType
    Private mvarCentered As Boolean
    Private mvarStyle As ttStyleEnum
    Private mvarTipText As String
    Private mvarVisibleTime As Long
    Private mvarDelayTime As Long'private data
    Private m_lTTHwnd As Long ' hwnd of the tooltip
    Private m_lParentHwnd As Long ' hwnd of the window the tooltip attached to
    Private ti As TOOLINFOPublic Property Let Style(ByVal vData As ttStyleEnum)
       'used when assigning a value to the property, on the left side of an assignment.
       'Syntax: X.Style = 5
       mvarStyle = vData
    End PropertyPublic Property Get Style() As ttStyleEnum
       'used when retrieving value of a property, on the right side of an assignment.
       'Syntax: Debug.Print X.Style
       Style = mvarStyle
    End PropertyPublic Property Let Centered(ByVal vData As Boolean)
       'used when assigning a value to the property, on the left side of an assignment.
       'Syntax: X.Centered = 5
       mvarCentered = vData
    End PropertyPublic Property Get Centered() As Boolean
       'used when retrieving value of a property, on the right side of an assignment.
       'Syntax: Debug.Print X.Centered
       Centered = mvarCentered
    End PropertyPublic Function Create(ByVal ParentHwnd As Long) As Boolean
       Dim lWinStyle As Long
       
       If m_lTTHwnd <> 0 Then
          DestroyWindow m_lTTHwnd
       End If
       
       m_lParentHwnd = ParentHwnd
       
       lWinStyle = TTS_ALWAYSTIP Or TTS_NOPREFIX
       
       ''create baloon style if desired
       If mvarStyle = TTBalloon Then lWinStyle = lWinStyle Or TTS_BALLOON
        
       m_lTTHwnd = CreateWindowEx(0&, _
          TOOLTIPS_CLASSA, _
          VBNullString, _
          lWinStyle, _
          CW_USEDEFAULT, _
          CW_USEDEFAULT, _
          CW_USEDEFAULT, _
          CW_USEDEFAULT, _
          0&, _
          0&, _
          App.hInstance, _
          0&)
                   
       ''now set our tooltip info structure
       With ti
          ''if we want it centered, then set that flag
          If mvarCentered Then
             .lFlags = TTF_SUBCLASS Or TTF_CENTERTIP Or TTF_IDISHWND
          Else
             .lFlags = TTF_SUBCLASS Or TTF_IDISHWND
          End If
           
          ''set the hwnd prop to our parent control's hwnd
          .hwnd = m_lParentHwnd
          .lId = m_lParentHwnd '0
          .hInstance = App.hInstance
          '.lpstr = ALREADY SET
          '.lpRect = lpRect
          .lSize = Len(ti)
       End With
       
       ''add the tooltip structure
       SendMessage m_lTTHwnd, TTM_ADDTOOLA, 0&, ti   ''if we want a title or we want an icon
       If mvarTitle <> VBNullString Or mvarIcon <> TTNoIcon Then
          SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
       End If   If mvarForeColor <> Empty Then
          SendMessage m_lTTHwnd, TTM_SETTIPTEXTCOLOR, mvarForeColor, 0&
       End If   If mvarBackColor <> Empty Then
          SendMessage m_lTTHwnd, TTM_SETTIPBKCOLOR, mvarBackColor, 0&
       End If
       
       SendMessageLong m_lTTHwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, mvarVisibleTime
       SendMessageLong m_lTTHwnd, TTM_SETDELAYTIME, TTDT_INITIAL, mvarDelayTime
    End FunctionPublic Property Let Icon(ByVal vData As ttIconType)
       mvarIcon = vData
       If m_lTTHwnd <> 0 And mvarTitle <> Empty And mvarIcon <> TTNoIcon Then
          SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
       End If
    End PropertyPublic Property Get Icon() As ttIconType
       Icon = mvarIcon
    End PropertyPublic Property Let ForeColor(ByVal vData As Long)
       mvarForeColor = vData
       If m_lTTHwnd <> 0 Then
          SendMessage m_lTTHwnd, TTM_SETTIPTEXTCOLOR, mvarForeColor, 0&
       End If
    End PropertyPublic Property Get ForeColor() As Long
       ForeColor = mvarForeColor
    End PropertyPublic Property Let Title(ByVal vData As String)
       mvarTitle = vData
       If m_lTTHwnd <> 0 And mvarTitle <> Empty And mvarIcon <> TTNoIcon Then
          SendMessage m_lTTHwnd, TTM_SETTITLE, CLng(mvarIcon), ByVal mvarTitle
       End If
    End PropertyPublic Property Get Title() As String
       Title = ti.lpStr
    End PropertyPublic Property Let BackColor(ByVal vData As Long)
       mvarBackColor = vData
       If m_lTTHwnd <> 0 Then
          SendMessage m_lTTHwnd, TTM_SETTIPBKCOLOR, mvarBackColor, 0&
       End If
    End PropertyPublic Property Get BackColor() As Long
       BackColor = mvarBackColor
    End PropertyPublic Property Let TipText(ByVal vData As String)
       mvarTipText = vData
       ti.lpStr = vData
       If m_lTTHwnd <> 0 Then
          SendMessage m_lTTHwnd, TTM_UPDATETIPTEXTA, 0&, ti
       End If
    End PropertyPublic Property Get TipText() As String
       TipText = mvarTipText
    End PropertyPrivate Sub Class_Initialize()
       InitCommonControls
       mvarDelayTime = 500
       mvarVisibleTime = 5000
    End SubPrivate Sub Class_Terminate()
       Destroy
    End SubPublic Sub Destroy()
       If m_lTTHwnd <> 0 Then
          DestroyWindow m_lTTHwnd
       End If
    End SubPublic Property Get VisibleTime() As Long
       VisibleTime = mvarVisibleTime
    End PropertyPublic Property Let VisibleTime(ByVal lData As Long)
       mvarVisibleTime = lData
    End PropertyPublic Property Get DelayTime() As Long
       DelayTime = mvarDelayTime
    End PropertyPublic Property Let DelayTime(ByVal lData As Long)
       mvarDelayTime = lData
    End Property
      

  2.   

    一个窗体,窗体上一个listview控件,代码如下:Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
       (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongConst LVM_FIRST = &H1000&
    Const LVM_HITTEST = LVM_FIRST + 18Private Type POINTAPI
        X As Long
        Y As Long
    End TypePrivate Type LVHITTESTINFO
       pt As POINTAPI
       flags As Long
       iItem As Long
       iSubItem As Long
    End TypeDim TT As CTooltip
    Dim m_lCurItemIndex As LongPrivate Sub Form_Load()
       With ListView1.ListItems
          .Add Text:="Test item #1"
          .Add Text:="Test item #2"
          .Add Text:="Long long long test item #3"
       End With   Set TT = New CTooltip
       TT.Style = TTBalloon
       TT.Icon = TTIconInfo
    End SubPrivate Sub ListView1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       Dim lvhti As LVHITTESTINFO
       Dim lItemIndex As Long
       
       lvhti.pt.X = X / Screen.TwipsPerPixelX
       lvhti.pt.Y = Y / Screen.TwipsPerPixelY
       lItemIndex = SendMessage(ListView1.hwnd, LVM_HITTEST, 0, lvhti) + 1
       
       If m_lCurItemIndex <> lItemIndex Then
          m_lCurItemIndex = lItemIndex
          If m_lCurItemIndex = 0 Then   ' no item under the mouse pointer
             TT.Destroy
          Else
             TT.Title = "Multiline tooltip"
             TT.TipText = ListView1.ListItems(m_lCurItemIndex).Text
             TT.Create ListView1.hwnd
          End If
       End If
    End Sub
      

  3.   

    Modest(塞北雪貂)·(偶最欣赏楼主的分)
    你好
    首先非常感谢你的帮忙!
    我按照你的方法
    TT.TipText = ListView1.ListItems(m_lCurItemIndex).Text得到的只是我的id值
    现在要得到的是对应id的温度,急。
    万分感谢各位指点一二
      

  4.   

    那就修改 TT.TipText = ListView1.ListItems(m_lCurItemIndex).Text 为:
    TT.TipText = ListView1.ListItems(m_lCurItemIndex).Text & ....
    变通一下嘛
      

  5.   

    谢谢,问题得到了很大的帮助,现在就是还有个问题
    我有一个查询按钮,有首记录,上一条记录,下一条记录,尾记录共5个按钮
             Id         温度    湿度    时间
             1 24.34 36.13 2007-4-25 17:06:35
    3 18.38 52.16 2007-1-17 9:39:46
    5 22.44 43.95 2007-1-17 9:41:34
    5 22.44 43.95 2007-1-17 9:41:37
    2 17.86 43.34 2007-1-17 9:58:13
    1 18.04 43.19 2007-1-17 9:59:11
    10 22.52 39.32 2007-1-17 10:02:05
    5 23.32 47.15 2007-1-17 10:02:23
    6 23.53 44.95 2007-1-17 10:02:29
    1 23.81 47.47 2007-1-17 10:02:34
    3 21.4 40.62 2007-1-17 10:13:07
    8 21.36 40.89 2007-1-17 10:14:01
    3 21.69 39.91 2007-1-17 10:16:13
    7 21.62 39.81 2007-1-17 10:16:33
    2 20.57 43.52 2007-1-17 10:10:10
    现在我点查询按钮把数据库的书库查找出来了,现在要不知道点击下一条记录的代码如何写,.MovePrevious MoveNext都试过了,55555举个例子比如现在id=1的第一条记录的温度值是24.34,id=2的第一条记录的温度值是17.86,id=3的第一条记录的温度值是18.38,。现在我每个id的第一条记录我已经都读出来了,现在关键要读取第二条记录,如这所示id=1的第二条记录的温度值是18.04,id=2的第二条记录的温度值是20.57,id=3的第二条记录的温度值是21.4,用MoveNext试过不行,各位帮忙想个办法。小弟先谢过各位了
      

  6.   

    TT.TipText   =   ListView1.ListItems(m_lCurItemIndex).Text   为: 
    TT.TipText   =   ListView1.ListItems(m_lCurItemIndex).Text   &   ....