VB里的listview复选框疑问

janselin 2008-12-23 09:34:21
vb里listview我选择了带复选框,但是默认是可以同时选中多条记录的复选框.
请问如何才能只可以选择一个复选框么?
简单点说,就是我选择了某条记录的复选框,之前选中的复选框勾勾自动去掉?
新手请教,请大家帮忙
...全文
713 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
SYSSZ 2008-12-25
  • 打赏
  • 举报
回复
改成这样试一试
Private Sub LsV_ItemCheck(ByVal Item As MSComctlLib.ListItem) 

Dim j As Integer
For j = 1 To LsV.ListItems.Count
LsV.ListItems(j).Checked = False

Item.Checked = True
Next
TxtInvCode.Text = Item '母件名称
TxtcInvName.Text = Item.SubItems(1) '母件名称
TxtcInvStd.Text = Item.SubItems(6) '规格型号
TxtUnitName.Text = Item.SubItems(7) '计量单位
TxtBomId.Text = Item.SubItems(2) '版本号
TxtBomDec.Text = Item.SubItems(4) '版本说明
TxtBomDate.Text = Item.SubItems(5) '版本日期
Txtkhcode.Text = Item.SubItems(3) '客户编码
End Sub
janselin 2008-12-25
  • 打赏
  • 举报
回复
当别的复选框被选中,前面选择复选框前面的勾勾去掉以后,自动清除显示在边上的MSHFlexGrid里面的数据.更新为新数据.
这个谁能帮帮我,加分求助啊
janselin 2008-12-25
  • 打赏
  • 举报
回复
我根据自己的情况更改了代码:
Private Sub LsV_ItemCheck(ByVal Item As MSComctlLib.ListItem)

Dim j As Integer
For j = 1 To LsV.ListItems.Count
LsV.ListItems(j).Checked = False

Item.Checked = True

TxtInvCode.Text = LsV.ListItems(j) '母件名称
TxtcInvName.Text = Item.SubItems(1) '母件名称
TxtcInvStd.Text = Item.SubItems(6) '规格型号
TxtUnitName.Text = Item.SubItems(7) '计量单位
TxtBomId.Text = Item.SubItems(2) '版本号
TxtBomDec.Text = Item.SubItems(4) '版本说明
TxtBomDate.Text = Item.SubItems(5) '版本日期
Txtkhcode.Text = Item.SubItems(3) '客户编码

Next

End Sub

目前运行的问题是:listview的第一列"母件名称"总是不能正确显示在TxtInvCode.Text里面.但是别的text都正常
TxtInvCode.Text里面固定显示为最后一行的第一列的"母件名称"
请大家再帮我看看代码哪里需要更改下?
SYSSZ 2008-12-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 janselin 的回复:]
就是不管listview里面有没有重复的记录,始终只能单选一个checkbox?
[/Quote]
用索引或用Key识别: 如
Option Explicit

Private Sub Form_Load()
Dim I As Integer
ListView1.ColumnHeaders.Add , , "MUN"
ListView1.View = lvwReport
For I = 1 To 9
ListView1.ListItems.Add , "A" & I, I
Next
ListView1.ListItems.Add , "A" & 10, 5
End Sub

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Dim I As Integer
Dim S As String
S = Item.Key
For I = 1 To ListView1.ListItems.Count
If ListView1.ListItems(I).Key <> S Then
ListView1.ListItems(I).Checked = False
End If
Next
End Sub
vansoft 2008-12-24
  • 打赏
  • 举报
回复
你点一个叫"Name"的,你把所有叫"Name"的全勾上不就行了.
janselin 2008-12-24
  • 打赏
  • 举报
回复
就是不管listview里面有没有重复的记录,始终只能单选一个checkbox?
janselin 2008-12-24
  • 打赏
  • 举报
回复
不错,谢谢兄弟,
但是还有个小问题,就是如果我listview里面有多个相同名字比如(F3110211)的话,则可以连续选中多个...直到你选了不同名字的记录.这个怎么避免?
SYSSZ 2008-12-24
  • 打赏
  • 举报
回复
我们回贴为了抢时间,没用Option Explicit强制变量声明,你的估计用了Option Explicit关键字,每一个变量都要声明,这不是错误
SYSSZ 2008-12-24
  • 打赏
  • 举报
回复
加dim s As string
janselin 2008-12-24
  • 打赏
  • 举报
回复
怎么到我这儿就成了"变量未定义"呢?
s = item这行
far021 2008-12-24
  • 打赏
  • 举报
回复
up
xixihaha_2011_098 2008-12-24
  • 打赏
  • 举报
回复

Private Sub Form_Load()
Me.ListView1.ListItems.Add "1", "'1'", "1"
Me.ListView1.ListItems.Add "2", "'2'", "2"
Me.ListView1.ListItems.Add "3", "'3'", "3"
Me.ListView1.ListItems.Add "4", "'4'", "4"
Me.ListView1.ListItems.Add "5", "'5'", "5"
End Sub
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Dim i As Integer
For i = 1 To ListView1.ListItems.Count
ListView1.ListItems(i).Checked = False
Next
Item.Checked = True
End Sub
SYSSZ 2008-12-23
  • 打赏
  • 举报
回复


Private Sub Form_Load()
ListView1.ColumnHeaders.Add , , "MUN"
ListView1.View = lvwReport
For I = 1 To 10
ListView1.ListItems.Add , , I
Next
End Sub

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
S = Item
For I = 1 To ListView1.ListItems.Count
If ListView1.ListItems(I) <> S Then
ListView1.ListItems(I).Checked = False
End If
Next
End Sub

7,763

社区成员

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

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