I am a student This is my very first post in this forum. I have been taking this class in C# concentrating on window forms. I have for the most part been able to figure out how to do what I have been assigned without outside help. My grade to this point is 96% +. I post all the previous information to let anyone who would answer this post that I am not asking any one to do the assigment I am about describe. All I want is a sample piece of code that I can use to accomplish this assignment.

To start with I have a form that has a list box, 6 text boxes and 3 buttons There are supposed to be 20 names in the listbox with this format "Doe, John" The Text boxes are places to display the first name, last name, street address, city, State, and finally the zipcode The programs must have the funtionalbity to display all names in the listbox in alphabetical order( this part no Problem). Each one of the names has its respective associated data. My problem is this I don't know how enter the data in an array and then match that data with the respective owner of that data what data to display is determined by the user of the program. Please
help I have to have this assignment turned in by Sunday Thank you in advance

7 Years
Discussion Span
Last Post by ddanbe


I have looked at the page you sent me to but it is still confusing below is my code so far and it is not doing what I need

private void nameInfo_SelectedIndexChanged(object sender, EventArgs e)
         //declares the array
            String[,] nameInfo = new String[,];
            nameInfo[0][0][0][0][0][0] = nameInfo_SelectedIndexChanged ["Oprah"]["Winfry"]["123 Harpo"]
            nameInfo[1][1][1][1][1][1] = nameInfo_SelectedIndexChanged ["Keith"]["Hopkins"]["456 Hopkins Rd"]
            nameInfo[2][2][2][2][2][2] = nameInfo_SelectedIndexChanged["Benedict"]["Arnold"]["789 Hanging Way"]
                ["Traitorville"]["New Jersey"]["10112"];
    for (int counter = 2; counter >= 0; counter--)
        fnameTxBx.Text += nameInfo_SelectedIndexChanged;  

Attached is an image of what the form that I trying to code looks like
the object is to take a selected entry and display respective information gathered in the array.

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

Attachments proj10.jpg 33.01 KB

You are making your life hopelessly complicated.
Lets take this step by step: Add a class to your project and call it nameInfo.
public class nameInfo
public string firstName;
public string lastName;
public string streetAdress;
// and so on
Now look again at the code sample in the other thread and see if you can work it out.
If not, let us know.


Hi RogerBailey welcome at DANIWEB!
Well, why not have a look at this thread http://www.daniweb.com/forums/thread239525.html and I believe your problem is solved.

Hi I believe that thread is a bit confusing. What Roger is seeking is to select an item in the listbox and display the address, city, state and zip of that person.

I have seen a post called Experiment Listbox in C#, that show to select an item in the listbox and display it in the label, but I tried the code in a new project and does not display the content to the label.

Now supposedly that a user enters all information about a person from lastname to zip code full address information.

Now the name of the person is listed in the listbox.
Now the user select a person name in the listbox and all the information that was previously entered will display in the textbox.

The school assignment in question uses an array and the selected index changed because that is where the selection will be made and the rest of the information is displayed in the textboxes.

What are your thoughts?


Desi Bravo


Could you explain what you find confusing about the thread?
What I wanted to do is, you have a list of info objects or structs. Select a name in a listbox, find that name in the list and drop the additional info in the textboxes or labels.
I tried the snippet by vegaseat and found ther was nothing wrong with it.

Edited by ddanbe: n/a


ddanbe is correct in his breakdown of the problem, you can create a Class/Struct to store each persons data, then store all the objects in a List<> collection.
When the selectedIndex of the listbox is changed you either iterate through each item in the list to find the match or use the List.Find() method with a predicate delegate.
Once you find the item, you read the users info out of it and display it on the form.

I realise your deadline has passed for this, but if you want code examples for this for future reference let me know :)

@bravo659, you should avoid bringing up your own questions in other threads, but have you checked to ensure the SelectedIndexChanged event handler has been created on your ListBox when you tried the Experiments with a ListBox (C#)
code? this.listBox1.SelectedIndexChanged += new System.EventHandler(this.ListBox1SelectedIndexChanged);


Yes, I tried it again and it worked fine.
I had to double click on the lsitbox in design time.
Sorry for my confusion and I will refrain from posting to other threads other than mine. Sorry about that, I truly appologize.



Hello ddanbe,
there is nothing wrong with it I tried it again liek I told Ryshad I had to double click on the listbox and insert the code and it worked like a charm. Now I am trying to implement similar to the project I am working on. But then I have to do what you told me first. But need to understand what I am doing first. That is why I am asking questions.



You can never ask too many questions... But perhaps we will continue in the thread you started yourself:)

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.