• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VB 2005: Catch exceutive on with ListView1 statement

mark103

Junior Member
Hey people!


I am new on this forum, i need your help please. I have catch the executive which gives me the trouble I have got. I am using two different records which one has with a image and one do not have a image. I am trying to get rid of the image box on With ListView1 statement if the images is not found in the records of my database. I would like to use Listview1.SmallImageList = ImageList1 if the images is found in the records and fill the images on my listview, otherwise set Listview1.SmallImageList = Nothing if the images is not found.



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dblIP As Double
dblIP = Dot2LongIP(TextBox1.Text)

Dim con As New OleDb.OleDbConnection()
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source =IPCountry.mdb "
Dim strCountry As String
Dim olecommand As New OleDb.OleDbCommand("SELECT country FROM ip2country WHERE " & dblIP & " BETWEEN begin_num AND end_num ;", con)
olecommand.Connection.Open()
strCountry = olecommand.ExecuteScalar()
con.Close()


If Not strCountry Is Nothing Then
strCountry = CountryName(strCountry)
MessageBox.Show(strCountry)
ListView1.Clear()
'Connect to the database and retreive the data required from Table1 into a datatable object.
Dim da As New System.Data.OleDb.OleDbDataAdapter( _
"SELECT Car, Images FROM Table1 WHERE Field1 = '" & strCountry & "' ORDER BY Car DESC", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = db1_test.mdb;Persist Security Info=False;")
Dim dt As New DataTable
da.Fill(dt)

' Place a new imagelist control onto your form designer window. The following
' will assign the listview to read from this control.
ImageList1.Images.Clear()
With ListView1
.LargeImageList = ImageList1
.SmallImageList = ImageList1
End With

Dim img As Image = Nothing
Dim imgIndex As Integer = 0
Dim carName As String = String.Empty
Dim listItem As ListViewItem = Nothing
' Loop through each row in the database.
For Each row As DataRow In dt.Rows
' First off, check we have a car name.

If Not IsDBNull(row.Item("Car")) Then
carName = CStr(row.Item("Car"))
'We have a car, so add it to the listview
listItem = ListView1.Items.Add(carName)
'Now we check to see if we have an image for this car
If Not IsDBNull(row.Item("Images")) Then
Using ms As New IO.MemoryStream(DirectCast(row.Item("Images"), Byte()))
img = Image.FromStream(ms)
ImageList1.Images.Add("Img" & imgIndex, img)
listItem.ImageIndex = imgIndex
imgIndex += 1



.LargeImageList = Nothing
.SmallImageList = Nothing
End With
End Using
End If
End If
Next
Return
End If
End Sub


Please can you help me how to get rid of the images box if the images is not found?? It should do with With Listview1 statement which they have a job to display the images. I did rid it which it works but i need them because I have some images in the records.



Hope you guys can help me to get this resolve.



Thanks,
Mark
 
yes I am trying to get rid of the entire on my listview which it is SmallImages only if the images is not found.



Hope you can help!!!!!!!!!!
 
Probably can just turn the thing invisible if it's empty. Better off that way then removing the whole control, I'd imagine.


Likely want something like this right before the end sub:

If imagelist1.images.count = 0
listview1.visible = false
else
listview1.visible = true
end if



 
thanks for your input. I have tested the code you post and unfortunately none of it are works. My application have filled a blank record, it should be removing the images box if the images from the record is not found. Can you assist me what to do and how to focus the project to fill the data and remove the images box on my listview??




thanks,
mark
 
Back
Top