Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 4355|回复: 3

[已解决]listview 单击后的光标定位问题

[复制链接]
发表于 2013-2-10 21:42 | 显示全部楼层 |阅读模式
listview 单击后的光标想定位在combobox的倒数第2位上,但只能瞬间实现。能否作到永远定位在倒数第2位上。
ComboBox1.SetFocus即使写了2次也没效果。
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
    strCondition = Item.Text & " = ''"
    ComboBox1.SetFocus
    ComboBox1.Value = strCondition
    ComboBox1.SelStart = Len(ComboBox1.Value) - 1
    ComboBox1.SetFocus
End Sub

Book1.rar (9.31 KB, 下载次数: 33)
发表于 2013-2-10 22:01 | 显示全部楼层    本楼为最佳答案   
Private Sub ListView1_Click()
    strCondition = ListView1.SelectedItem.Text & " = ''"
    With ComboBox1
        .SetFocus
        .Value = strCondition
        .SelStart = Len(ComboBox1.Value) - 1
    End With
End Sub
回复

使用道具 举报

发表于 2013-2-10 22:45 | 显示全部楼层
可以在ComboBox上加一个MouseDown触发事件,同时精简一下ListView1_ItemClick的代码
  1. Private Sub ComboBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  2.    If Len(ComboBox1.Value) > 0 Then ComboBox1.SelStart = Len(ComboBox1.Value) - 1
  3. End Sub

  4. Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
  5.     strCondition = Item.Text & " = ''"
  6.     ComboBox1.Value = strCondition
  7. End Sub
复制代码

Book1.rar

12.58 KB, 下载次数: 97

回复

使用道具 举报

 楼主| 发表于 2013-2-11 09:43 | 显示全部楼层
谢谢各位,新年快乐。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-2 13:23 , Processed in 0.264207 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表