Selecting only one fieldin ListView

LoGaN-ES

New member
Joined
Jul 2, 2009
Messages
2
Programming Experience
1-3
Hi!

I am a bit a newbie in VB.NET, and I am trying to make some sort of product catalog
which will pull data from Access database.The data is displayed in ListView, and I have
2 problems.

1.The following code is for display data text for each selected row from ListView(which is in details):
------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub ListView1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick

Try
Dim str As String
Dim j As Byte
str = ListView1.Columns(0).Text & " ..." & ListView1.SelectedItems(0).Text
For j = 1 To ListView1.Columns.Count - 1
str = str & ListView1.Columns(j).Text & " ... " & ListView1.SelectedItems(0).SubItems(j).Text
Next

TextBox1.Text = str

Catch exp As Exception

End Try
-----------------------------------------------------------------------------------------------------------------------------------------------------------
I am displayed all data as text from whole row, but I want only to display data from one field in row that is selected.

2.I have in my database a picture for a each row as OLE object, and I want do display that picture in PictureBox for a item that is
selected in ListView.I am using a OleDbConnection to populate ListView from database:
-------------------------------------------------------------------------------------------------------------------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
oledbcon.Open()
strSQL = "SELECT * FROM MaticnePloce"
cmd = New OleDbCommand(strSQL, oledbcon)
objRead = cmd.ExecuteReader
While objRead.Read
lv = Me.ListView1.Items.Add(objRead("SifraArtikla") & (""))
lv.SubItems.Add(objRead("NazivArtikla") & "")
lv.SubItems.Add(objRead("JM") & "")
End While

objRead.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
oledbcon.Close()
End Try


End Sub
-------------------------------------------------------------------------------------------------------------------------------
Any suggestion I will appriciate.Greetz!
 
I am displayed all data as text from whole row, but I want only to display data from one field in row that is selected.
Only get the Text of the desired subitem instead of all the subitems.
I have in my database a picture for a each row as OLE object, and I want do display that picture in PictureBox for a item that is
selected in ListView.
Create an Image object for each row and assign it to the Tag property of the corresponding ListViewItem. In the SelectedIndexChanged event handler you can get the Image and display it in the PictureBox. [ame="http://www.vbforums.com/showthread.php?t=469562"]Here[/ame] is an example of getting Images from a database.
 
Back
Top