adding a image to a imagelist during runtime

jnash

Well-known member
Joined
Oct 20, 2006
Messages
111
Programming Experience
Beginner
my image list is local and certain parts of my app needs it, how do i just add a picture picked up from a filedialogue box to it, im having so many issues with this

thanks
VB.NET:
  Dim temp As String
        OpenCustomerImage.ShowDialog()
        temp = OpenCustomerImage.FileName
        frmMain.iList.Images.Add()???
 
the thing is with that code is that it isnt adding a key(i need to remember what the key is for that pic cos i need it in other places), ive modified the code a bit see below: however it adds one image and displays it but when i try to add another the pic stays the same.


VB.NET:
    Private Sub btnAddPic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddPic.Click
        '     Dim temp As String
        '    OpenCustomerImage.ShowDialog()
        '   temp = OpenCustomerImage.FileName
        '  ilistNo = frmMain.ilistNo
        '
        '       Dim theImage As Image = Image.FromFile(temp)
        '      frmMain.iList.Images.Add(ilistNo, theImage)
        '     picCustomer.Image = frmMain.iList.Images.Item(ilistNo)
        '    ilistNo = ilistNo + 1
    End Sub
 
Debug 'ilistNo' variable, make sure about its value. The image key is type String (both with Add and Item), I don't know what your 'ilistNo' is, but it looks like a integer number, in which case you are setting this implicitly as string key, but when accessing Item you are actually getting it by integer index and not string key lookup.
 
Back
Top