首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

ListView控件+ImageList绑定数据库显示数据解决方案

2012-01-24 
ListView控件+ImageList绑定数据库显示数据各位帮个忙,现在有个要利用ListView控件+ImageList绑定数据库显

ListView控件+ImageList绑定数据库显示数据
各位帮个忙,现在有个要利用ListView控件+ImageList绑定数据库显示数据
下面是数据库中的2个表:监控温度表和Roomtemp表
监控温度表
                  id               温度             湿度                   时间
621.440.622007-1-17   10:13:07
821.3640.892007-1-17   10:14:01
321.6939.912007-1-17   10:16:13
1021.6239.812007-1-17   10:16:33
220.5743.522007-1-17   10:10:10
1520.6341.352007-1-17   10:18:51
522.5338.852007-1-17   10:10:10
221.2541.342007-1-17   10:22:18
621.8939.902007-1-17   10:22:41
1221.8939.92007-1-17   10:22:44
222.9635.32007-1-17   10:25:02
1222.0835.712007-1-17   10:25:34
2022.0835.712007-1-17   10:25:43
521.5437.572007-1-17   10:27:23
122.2537.472007-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   Integer

If   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



[解决办法]
一个窗体,窗体上一个listview控件,代码如下:

Option Explicit

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

Const LVM_FIRST = &H1000&
Const LVM_HITTEST = LVM_FIRST + 18

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Type LVHITTESTINFO
pt As POINTAPI
flags As Long
iItem As Long
iSubItem As Long
End Type

Dim TT As CTooltip
Dim m_lCurItemIndex As Long

Private 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 Sub

Private 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

[解决办法]
TT.TipText = ListView1.ListItems(m_lCurItemIndex).Text 为: 
TT.TipText = ListView1.ListItems(m_lCurItemIndex).Text & .... 

热点排行