Select ListView Item Programmatically, 程序编码编程实现自动选择ListView的Item项目条目

本文介绍了一种简单的方法来程序化地选中 ListView 中的项。通过创建一个按钮并为其添加点击事件,可以在点击按钮时选中 ListView 的第一项。此方法虽简单却非常实用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  This simple code will allow you to programmatically select an item in a listview. Hope this helps.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				
	
		
		
		
	
	
		

How to select a ListView Item Programmatically.

 

This is a simple process, but most people forget a little step in doing this.

Step 1:

Create a ListView Item and name it to whatever you wish. I will use lv for simplicity.

Step 2:

Create a Button Item

Step 3:

Double Click the Button to start typeing code.

 

Step 4:

Enter the following code:

Private Sub Button1_Click(......) Handles Button1.Click

      lv.Items(0).Selected = True

      lv.Select() 'This is what most people forget. If you don't put this in here, it will never select the item in the list view.

End Sub

And that is it! Really Really simple, but very useful.

 

Step 5:

If you find this code useful. Vote for me.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值