944,068 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 150812
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 5th, 2006
0

ListView in VB.Net

Expand Post »
Hi,
Anyone of you know hot to get item when user click on item in the listview. I want the data in listview display in the text box, can anyone give me some advice on this? The following code is my coding at Form_Load():-

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Set the List to Detail View
ListView1.View = View.Details
ListView1.CheckBoxes = True

'To Activate an Item you must doubleclick the item
'This will fire the
ListView_OrderEntry.Activation = ItemActivation.TwoClick

'Add Columns
ListView1.Columns.Add("C1", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C2", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C3", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C4", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C5", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C6", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C7", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C8", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C9", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("C10", 100, HorizontalAlignment.Center)
End Sub
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
khwo is offline Offline
12 posts
since Jun 2006
Jul 9th, 2006
0

Re: ListView in VB.Net

Hi,

You can use SelectedIndexChange event of ListView class.

Loren Soth
Reputation Points: 28
Solved Threads: 4
Posting Whiz in Training
Lord Soth is offline Offline
233 posts
since Mar 2006
Aug 9th, 2006
0

Re: ListView in VB.Net

Code to fill the listview control in vb.net dynamically

Dim
rdGetData As SqlClient.SqlDataReader
Try
If ListView1.Items.Count > 0 Then
ListView1.Items.Clear()
End If
SQLCmd.CommandType = CommandType.Text
SQLCmd.CommandText = "SELECT * from table"
rdGetData = SQLCmd.ExecuteReader

Dim intCount As Decimal = 0
While rdGetData.Read
ListView1.Items.Add(Trim("FieldName")) 'col no. 1
ListView1.Items(CInt(intCount)).SubItems.Add(Trim(rdGetContactsInfo("FieldName"))) 'col no. 2
ListView1.Items(CInt(intCount)).SubItems.Add(Trim(rdGetContactsInfo("FieldName"))) 'col no. 3
intCount = intCount + 1
End While
rdGetData.Close()
rdGetData = Nothing

Catch Exp As Exception
intNumError = Err.Number()
MsgBox("[ " & CStr(intNumError) + " ] " + Err.Description, MsgBoxStyle.Critical, " (Program Error)")
End Try



Code to get selected item in the textbox control into the button's click event or according to your requirment.



TextBox1.Text = ListView1.SelectedItems(0).Text
TextBox2.Text = ListView1.SelectedItems(0).SubItems(2).Text

This will copy the selected item's first value and 2nd value into the textboxes
Last edited by Tanvir; Aug 9th, 2006 at 2:15 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tanvir is offline Offline
3 posts
since Aug 2006
Aug 9th, 2006
0

Re: ListView in VB.Net

hi,
You can use the following code to display the selected text in the textbox.

Private
Sub ListView1_ItemDrag(ByVal sender AsObject, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag
TextBox1.Text = e.Item.ToString
End Sub


Regards

Exelio
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Exelio is offline Offline
57 posts
since Aug 2006
Oct 14th, 2009
0

Quick Note

Click to Expand / Collapse  Quote originally posted by Exelio ...
hi,
You can use the following code to display the selected text in the textbox.

Private
Sub ListView1_ItemDrag(ByVal sender AsObject, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag
TextBox1.Text = e.Item.ToString
End Sub


Regards

Exelio
Perhaps you can use e.Item.ToString for an ItemDrag event, however I think he is using the ItemActivate event, in which case, this will not work. Why VB does this is beyond me. ListViews have been a pain to learn in general.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
giNMaN86 is offline Offline
1 posts
since Oct 2009
Nov 24th, 2009
0
Re: ListView in VB.Net
thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ola awny is offline Offline
1 posts
since Nov 2009
Jul 23rd, 2010
0
Re: ListView in VB.Net
'here i've got a listview1 ,label1 .
'as simple as this one. it displays the corresponding item from the listview1 straight to the 'label1 ..

Private Sub listview1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles listview1.ItemSelectionChanged

Label1.Text = e.Item.Text

End Sub


'or if you want the next column-item to be displayed, let say label2 from the same listview, then just the code

Label2.Text = e.Item.SubItems(1).Text

'(0) for the first column ,(1) for the 2nd, and so on.

note: this was coded in Visual Studio 2008, so i never tried the same code in VB.Net but i think it works the same.
Last edited by pergsify; Jul 23rd, 2010 at 10:53 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pergsify is offline Offline
1 posts
since Jul 2010
Sep 3rd, 2010
0
Re: ListView in VB.Net
sfdasdfa
Reputation Points: 10
Solved Threads: 0
Newbie Poster
noelcahapon is offline Offline
1 posts
since Sep 2010
May 10th, 2011
0
Re: ListView in VB.Net
You should use the mouse click event and the code below

Dim itm as ListViewItem = Me.prvLstVw.GetItemAt(e.X, e.Y)

If itm is nothing Then
Exit Sub
End If
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kevin m cain is offline Offline
1 posts
since May 2011
Sep 22nd, 2011
0
Re: ListView in VB.Net
You should use
textbox1.text = ListView1.SelectedItems.Item(0).Text
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Gumagur is offline Offline
1 posts
since Sep 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How to extract data in sql and use it in repeater
Next Thread in VB.NET Forum Timeline: Sorting 3 numbers ascending and descending





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC