Jump to content
xisto Community
Sign in to follow this  
iGuest

code to make an editable listview item for vb.net VB.NET: Problem With Listview Controls

Recommended Posts

code to make an editable listview item for vb.netVB.NET: Problem With Listview Controls

Please give me some code on how to make a listivew item which index is 4 to be editable..

question by Arnold

Keywords:

Share this post


Link to post
Share on other sites

It looks like the original poster was naughty and got himself banned. Anyway here is a solution for anyone else who needs it.

Setup
â˘Create new project called EditListviewExample in Visual basic 2008
â˘Add listview called lvMain
â˘Add Item1, Item2, Item3, Item4, and Item5 as Items using the design view
â˘Change View to list
â˘Add a button named btnGet, numericupdown named nudGet, and a textbox named txtGet
â˘Add a button named btnPut, numericupdown named nudPut, and a textbox named txtPut
â˘Add Option Strict On and Option Explicit On to the code

Option Strict OnOption Explicit OnPublic Class frmMain	Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click		'This is to check and see if the index provided by nudGet is a valid index, otherwise		'and exception will be thrown.		If CInt(nudGet.Value) < lvMain.Items.Count Then			'the values of a listview is held in the .items property			txtGet.Text = lvMain.Items(CInt(nudGet.Value)).Text		Else			MessageBox.Show("Selection falls outside of the bounds of the listview")		End If	End Sub	Private Sub btnPut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPut.Click		'This is to check and see if the index provided by nudPut is a valid index, otherwise		'and exception will be thrown.		If CInt(nudPut.Value) < lvMain.Items.Count Then			lvMain.Items(CInt(nudPut.Value)).Text = txtPut.Text		Else			MessageBox.Show("Selection falls outside of the bounds of the listview")		End If	End SubEnd Class

The way to access any value within a listview is to access the item() property of the listview. This example will get the item value specified by the numericupdown or conversely put a value in the select item. You must realize that a listview is zero based like most other .NET controls and structures. If you get the value from the first slot you should ask for item(0).

The listview is an incredible powerful control and you can do some very amazing things with it. You can also get the highlighted item by using selecteditems() or get the item under the mouse by using getimageat().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.