ListView in VB.Net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2006
Posts: 12
Reputation: khwo is an unknown quantity at this point 
Solved Threads: 0
khwo khwo is offline Offline
Newbie Poster

ListView in VB.Net

 
0
  #1
Jul 5th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 233
Reputation: Lord Soth is an unknown quantity at this point 
Solved Threads: 4
Lord Soth's Avatar
Lord Soth Lord Soth is offline Offline
Posting Whiz in Training

Re: ListView in VB.Net

 
0
  #2
Jul 9th, 2006
Hi,

You can use SelectedIndexChange event of ListView class.

Loren Soth
Best regards,
Loren Soth

Crimson K. Software _________________________________________________________________ Crimson K. Blog
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 3
Reputation: Tanvir is an unknown quantity at this point 
Solved Threads: 0
Tanvir Tanvir is offline Offline
Newbie Poster

Re: ListView in VB.Net

 
0
  #3
Aug 9th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 57
Reputation: Exelio is an unknown quantity at this point 
Solved Threads: 0
Exelio Exelio is offline Offline
Junior Poster in Training

Re: ListView in VB.Net

 
0
  #4
Aug 9th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: giNMaN86 is an unknown quantity at this point 
Solved Threads: 0
giNMaN86 giNMaN86 is offline Offline
Newbie Poster

Quick Note

 
0
  #5
Oct 14th, 2009
Originally Posted by Exelio View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: ola awny is an unknown quantity at this point 
Solved Threads: 0
ola awny ola awny is offline Offline
Newbie Poster
 
0
  #6
4 Days Ago
thank you
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC