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.
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
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