Click here to Skip to main content
15,900,378 members
Home / Discussions / C#
   

C#

 
GeneralRe: Exchange Server Address Book Pin
FredSP6-Sep-04 2:49
FredSP6-Sep-04 2:49 
GeneralRe: Exchange Server Address Book Pin
Corinna John6-Sep-04 3:41
Corinna John6-Sep-04 3:41 
GeneralSocket remote node disconnection Pin
Den2Fly5-Sep-04 18:08
Den2Fly5-Sep-04 18:08 
GeneralRe: Socket remote node disconnection Pin
Pradeep Shamarao5-Sep-04 21:47
Pradeep Shamarao5-Sep-04 21:47 
GeneralCustomizing a ListBox Pin
eggie55-Sep-04 16:58
eggie55-Sep-04 16:58 
GeneralRe: Customizing a ListBox Pin
mav.northwind6-Sep-04 2:35
mav.northwind6-Sep-04 2:35 
GeneralRe: Customizing a ListBox Pin
Werdna6-Sep-04 9:49
Werdna6-Sep-04 9:49 
GeneralRe: Customizing a ListBox Pin
eggie56-Sep-04 19:32
eggie56-Sep-04 19:32 
Hey man, thanks for you help. I have made an implimentation of it below.

namespace listBoxTest
{
    partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Customer customer=new Customer(this.textBox1.Text, this.textBox2.Text);

            this.listBox1.Items.Add(customer.firstName);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Customer cust=(Customer)listBox1.SelectedItem;

            this.asdfStatusStripPanel.Text=cust.firstName+" "+cust.lastName;
        }
    }

    public class Customer
    {
        public string firstName;
        public string lastName;

        public Customer(string FirstName, string LastName)
        {
            firstName = FirstName;
            lastName = LastName;
        }
    }
}


My question was regarding the code inside my listBox1_SelectedIndexChanged and the button1_Click methods. When I just add a Customer to the listBox all the code works fine, but I can't see any firstName or lastName in the listBox (which is completely understandable). Now, when I add a Customer.firstName, does that now copy the whole Customer object to the list, or does it just copy the firstName object? I think it just copyies the object (string) firstName, 'cause in listBox1_SelectedIndexChanged when I try to add the data to the class, I get an InvalidCastException.

Any idea how I can still add the (string) representation of the Customer.firstName to the ListBox, but still have access to the whole object (class) in the listBox1_SelectedIndexChanged method?

/\ |_ E X E GG
GeneralRe: Customizing a ListBox Pin
Werdna7-Sep-04 3:59
Werdna7-Sep-04 3:59 
GeneralRe: Customizing a ListBox Pin
eggie57-Sep-04 14:01
eggie57-Sep-04 14:01 
QuestionCan I use Visual C# Standard commercially? Pin
kusanagi20005-Sep-04 15:35
kusanagi20005-Sep-04 15:35 
AnswerRe: Can I use Visual C# Standard commercially? Pin
Christian Graus5-Sep-04 15:38
protectorChristian Graus5-Sep-04 15:38 
GeneralRe: Can I use Visual C# Standard commercially? Pin
kusanagi20005-Sep-04 16:33
kusanagi20005-Sep-04 16:33 
GeneralGradientPanel Pin
Asciono5-Sep-04 13:29
Asciono5-Sep-04 13:29 
GeneralRe: GradientPanel Pin
mav.northwind5-Sep-04 20:10
mav.northwind5-Sep-04 20:10 
GeneralMachine Info Pin
Moon Boy5-Sep-04 13:17
Moon Boy5-Sep-04 13:17 
GeneralRe: Machine Info Pin
eggie55-Sep-04 14:20
eggie55-Sep-04 14:20 
GeneralRe: Machine Info Pin
Mazdak5-Sep-04 20:39
Mazdak5-Sep-04 20:39 
GeneralRe: Machine Info Pin
heile6-Sep-04 19:10
heile6-Sep-04 19:10 
QuestionOnKeyDown not getting arrow keys ? Pin
Christian Graus5-Sep-04 12:30
protectorChristian Graus5-Sep-04 12:30 
AnswerRe: onkeydown not getting arrow keys ? Pin
Werdna6-Sep-04 9:53
Werdna6-Sep-04 9:53 
GeneralRe: onkeydown not getting arrow keys ? Pin
Christian Graus6-Sep-04 10:40
protectorChristian Graus6-Sep-04 10:40 
Generaldifferential comparison algo Pin
sho125-Sep-04 10:37
sho125-Sep-04 10:37 
GeneralRe: differential comparison algo Pin
Christian Graus5-Sep-04 12:31
protectorChristian Graus5-Sep-04 12:31 
GeneralRe: differential comparison algo Pin
mitchelle24-Oct-04 5:22
mitchelle24-Oct-04 5:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.