I'm on the very last feature of my program (a movie manager) thanks to the help that the people of the forums have so graciously provided me with so far; however, I'm stuck with a problem I describe below. It may look like a lot but once you understand what's going on, it seems like a pretty simple problem, but nevertheless still a problem I haven't been able to remedy yet.
To quickly understand what I'm doing, it might help for you to see a visual of my program (it crashed here so don't mind the white everywhere): http://i.imgur.com/rKdGrsP.png?1
' I utilize a datagridview which is the big white rectangle at the bottom
' The UPPER LEFT big rectangle whitebox is a PictureBox for the currently selected Movie, which works perfectly. I utilize this code in order to get the images for all the movies in the database
' The 4 white boxes are where the PictureBoxes will be loaded for each of the movies in a user's database. These have to be individually created and will go off to the right as long as they need to be.
' They are enclosed in a panel (black). Autoscroll is set to True so if the poster images go off the form to the right I can view those.
Since the number of movies in a user's database can vary greatly, I have a big For loop to do all my work which goes through as many rows as are counted (I call this The Mother Loop). Anyways, my current problem seems to be that I am not creating the PictureBox correctly, I outline where my program crashes in red:
To quickly understand what I'm doing, it might help for you to see a visual of my program (it crashed here so don't mind the white everywhere): http://i.imgur.com/rKdGrsP.png?1
' I utilize a datagridview which is the big white rectangle at the bottom
' The UPPER LEFT big rectangle whitebox is a PictureBox for the currently selected Movie, which works perfectly. I utilize this code in order to get the images for all the movies in the database
' The 4 white boxes are where the PictureBoxes will be loaded for each of the movies in a user's database. These have to be individually created and will go off to the right as long as they need to be.
' They are enclosed in a panel (black). Autoscroll is set to True so if the poster images go off the form to the right I can view those.
Since the number of movies in a user's database can vary greatly, I have a big For loop to do all my work which goes through as many rows as are counted (I call this The Mother Loop). Anyways, my current problem seems to be that I am not creating the PictureBox correctly, I outline where my program crashes in red:
Code:
' I'm getting a NullReferenceException currently where the red *** is located, however I KNOW that all the code that gets the image and sets it (denoted as *** in green) works since I have it working for the main poster image.
' The Mother Loop
For CurrentRowIndex As Integer = 0 To RowCount
Dim CurrentRow As DataGridViewRow = FilmsDataGridView.Rows(CurrentRowIndex)
FilmName = CurrentRow.Cells(0).Value.ToString
Dim URLText As String = RetrieveFilmInfo() ***
' Retrieves film poster image URL
Dim BeginString As String = URLText.IndexOf("http") ***
Dim EndString As String = URLText.IndexOf(""",""imdbRating""") ***
Dim PosterURL As String = URLText.Substring(BeginString, EndString - BeginString) ***
Dim Poster As PictureBox
' Retrieves film poster image
Dim ImageInBytes() As Byte = MyWebClient.DownloadData(PosterURL) ***
Dim ImageStream As New IO.MemoryStream(ImageInBytes) ***
Poster.Image = New System.Drawing.Bitmap(ImageStream) *** Here's where the error occurs, even though this code works for the main poster image, it doesn't work for "Poster"
' The following code sets the position of the Poster. Even numbers go on the top row, odd on the bottom as seen with the two different Y coordinates, 26 & 226. I haven't gotten this far yet due to the error described in red above.
Dim x = 2
If CurrentRowIndex = 0 Or CurrentRowIndex = 1 Then
x = 48 ' Beginning poster image column X coordinate
ElseIf CurrentRowIndex > 1 And CurrentRowIndex Mod 2 = 0 Then ' Changes X coordinate only if its on the next column of poster images
x += 188
End If
If CurrentRowIndex Mod 2 = 0 Then ' Even
Poster.Location = New Point(x, 26)
ElseIf CurrentRowIndex Mod 2 = 1 Then ' Odd
Poster.Location = New Point(x, 226)
End If
Poster.Image = ScaleImage(Poster.Image, 224) ***
Next