Jump to content

Using Listbox to change image in Picturebox!

- - - - -

  • Please log in to reply
7 replies to this topic

#1
rubbadrools

rubbadrools

    Newbie

  • Members
  • PipPip
  • 12 posts
Hello!

My problem is exactly as it says in the title :P
My goal is to have couple of items in the listbox and when highlighting one item a image in the picturebox should appear, and so on for each item in the listbox.
I just don't know how to change image depending on selected item in the listbox.
don't know if it's relevant but, my inputs in the listbox is from an arraylist.

If anyone is willing to aid in my needs I would greatly appreciate it!

Thanks in advance
Noobatron Rubbadrools

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Are you having trouble setting an image in the picturebox, detecting when something is selected in the listbox, detecting which item is selected in the listbox, or something else? Without seeing your current code, it is hard to determine where you're stuck.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
rubbadrools

rubbadrools

    Newbie

  • Members
  • PipPip
  • 12 posts
Ahh Sorry, I suck at explaining :P
It's setting a image in the picturebox when selecting a item from the listbox
like this:
*start form
*listbox gets filled with a bunch of names from the arraylist
*when a name is highlighted a picture will appear in the picturebox

something like that :P
I don't blame u if u didn't understand this explanation either and in that case i'll try again by printing :P

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I understand what you're trying to do. I don't understand which part of that you're having difficulty with. You've listed three steps. You could be having troubles starting a form, for all I know.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
rubbadrools

rubbadrools

    Newbie

  • Members
  • PipPip
  • 12 posts
The code issue is connecting the highlighted name to a picture that shows in the picturebox.
so when all the names are up in the list, I can press one name and another picture in the picturebox is shown.





using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Collections;


namespace laxa3._1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void Form1_Load(object sender, EventArgs e)

        {



            ArrayList nameList = new ArrayList();

            Namn namn1 = new Namn("John");

            Namn namn2 = new Namn("Katy");

            Namn namn3 = new Namn("Dan");



            nameList.Add(namn1);

            nameList.Add(namn2);

            nameList.Add(namn3);




            foreach (Namn obj in nameList)

                listBox1.Items.Add(obj.nNamn);

          /*  foreach (Namn obj in nameList)

                pictureBox1.Load("C:\\Users\\Arrian\\Documents\\Visual Studio 2010\\Projects\\Assignment3.1\\Assignment3.1\\bin\\" + n ".jpg");

         if (listBox1.SelectedIndex = )

            {


                pictureBox1.Load("C:\\Users\\Arrian\\Documents\\Visual Studio 2010\\Projects\\Assignment3.1\\Assignment3.1\\bin\\Katy.jpg");

                pictureBox1.Load("C:\\Users\\Arrian\\Documents\\Visual Studio 2010\\Projects\\Assignment3.1\\Assignment3.1\\bin\\Katy.jpg");


            }

           */

        }

                



            

    


        private void pictureBox1_Click(object sender, EventArgs e)

        {

            

        }

   



    

    

    

    }


}



Thats how far i've come, I have another class for the Arrays but I figured that isn't the important part atm

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
ListBox.SelectedItem Property (System.Windows.Forms)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
rubbadrools

rubbadrools

    Newbie

  • Members
  • PipPip
  • 12 posts
Thanks! I feel kinda stupid for not figuring this out myself but it's like when u do a puzzlebox and can't put the last pieces together... Sometimes all you need is a fresh pair of eyes ;)

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
No problem. MSDN + Google rocks.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users