关于ListView控件的基础问题(每问20)

VisualBUG 2005-04-30 05:39:43
初学Vb 对 ListView 控件不是很熟悉.但还必须得用到它.有几个问题希望能多帮帮忙.谢谢!
做了一个多客户端聊天程序.服务器在数据到达后这样处理了.
Private Sub WinsockSRV_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim RIp As String
Dim RPort As Integer
RIp = WinsockSRV(index).RemoteHostIP
RPort = WinsockSRV(index).RemotePort
List1.AddItem " Host Name " & RIp & RPort & index '添加一条新项
List1.ItemData(List1.NewIndex) = index '设置新添加项的ItemData值
End Sub

'在WinsockSRV的Close事件中
Private Sub WinsockSRV_Close(index As Integer)
Dim i As Integer
Dim LC As Integer
LC = List1.ListCount
For i = 0 To LC - 1
If List1.ItemData(i) = index Then
WinsockSRV(index).Close '相应的 SCK 关闭
List1.RemoveItem i
Exit For
End If
Next
End Sub
'在List的Click事件中
Private Sub List1_Click()
Dim GLI As Integer
GLI = List1.ItemData(List1.ListIndex)
MsgBox "你所选定项的ItemData是:" & GLI
End Sub
--------------------------------------
问题:
1.如果要用Listview控件添加的话.如何去写? 相关的 ItemData 如何去设置?
2.其次就是如何从Listview中很多项中删除某一项.其它的项ItemData不因删除某一项而发生改变.
3.假设有5项内容. 如何修改该项的某子项内容呢?
其实就是如何把上面的List代码变成Listview代码.
List控件添加使用List1.additem , 而Listview我则不会用.就是这个意思..
求例子谢谢.
...全文
156 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxcc 2005-05-04
  • 打赏
  • 举报
回复
再试试!
zuoxingyu 2005-05-01
  • 打赏
  • 举报
回复
Private Sub dcbUnit_Click()
lvEmployees.ListItems.Clear
Dim rs As New ADODB.Recordset
Dim strsql As String
strsql = "select e.id,e.name,u.Unit_Name,c.Class_Name from (employee e inner join unit u on e.unit= u.unit_ID) inner join class c on e.class=c.Class_Id where e.unit=" & Val(dcbUnit.Text) '& Left(dcbUnit.Text, 5)
rs.Open strsql, Adocnn, adOpenStatic, adLockReadOnly
While Not rs.EOF
Set itmX = lvEmployees.ListItems.Add(, , rs!ID)
itmX.SubItems(1) = rs!Name
itmX.SubItems(2) = rs!Unit_Name
itmX.SubItems(3) = rs!Class_Name
rs.MoveNext
Wend
Set rs = Nothing
End Sub
VisualBUG 2005-05-01
  • 打赏
  • 举报
回复
结贴时发现的..郁闷..又是这样.我已经联系管理员了.
加载xml文件错误,请跟斑竹联系!!请斑竹生成以下社区的贴子列表!!
roomid:5101
typenum:2
VisualBUG 2005-05-01
  • 打赏
  • 举报
回复
原来如此.
我又深入的看了些帖子.发现ListView是个神奇的控件.HOHO.
明白了许多.看来要多多练习啊.
Thanks !
jykuwang 2005-05-01
  • 打赏
  • 举报
回复
抢分.............吼吼
jykuwang 2005-05-01
  • 打赏
  • 举报
回复
ListView 没有 ItemData 这个属性,你可用 Key 来代替,很好用

1.ListView1.ListItems.Add , "A" & Index, " Host Name " & RIp & RPort & Index
2.(ListView 没有 ItemData 这个属性)
3.ListView1.ListItems.Remove ListView1.ListItems("A" & Index).Index


Private Sub WinsockSRV_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim RIp As String
Dim RPort As Integer
RIp = WinsockSRV(index).RemoteHostIP
RPort = WinsockSRV(index).RemotePort

'List1.AddItem " Host Name " & RIp & RPort & index'添加一条新项
'List1.ItemData(List1.NewIndex) = index '设置新添加项的ItemData值

ListView1.ListItems.Add , "A" & Index, " Host Name " & RIp & RPort & Index

End Sub

'在WinsockSRV的Close事件中
Private Sub WinsockSRV_Close(index As Integer)
' Dim i As Integer
' Dim LC As Integer
' LC = List1.ListCount
' For i = 0 To LC - 1
' If List1.ItemData(i) = index Then
' WinsockSRV(index).Close '相应的 SCK 关闭
' List1.RemoveItem i
' Exit For
' End If
' Next

ListView1.ListItems.Remove ListView1.ListItems("A" & Index).Index
Dim sKey As String
sKey = ListView1.ListItems("A" & Index).Key
sKey = Mid(sKey,2)
WinsockSRV(Val(sKey)).Close

End Sub

'在List的Click事件中
Private Sub List1_Click()
'Dim GLI As Integer
'GLI = List1.ItemData(List1.ListIndex)

Dim sKey As String
sKey = ListView1ListView1.SelectedItem.Key
sKey = Mid(sKey,2)

MsgBox "你所选定项的ItemData是:" & sKey

End Sub

.........................
好了吧
VisualBUG 2005-05-01
  • 打赏
  • 举报
回复
TOP
VisualBUG 2005-05-01
  • 打赏
  • 举报
回复
帮你顶啦~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧