Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
QuestionManaged and Unmanaged code Pin
3bood.ghzawi20-Jan-10 13:03
3bood.ghzawi20-Jan-10 13:03 
AnswerRe: Managed and Unmanaged code Pin
Bekjong20-Jan-10 15:53
Bekjong20-Jan-10 15:53 
AnswerRe: Managed and Unmanaged code Pin
Abhinav S20-Jan-10 17:33
Abhinav S20-Jan-10 17:33 
QuestionDisplay highlighted data from Listbox in Textboxes Pin
CarlMartin1020-Jan-10 13:02
CarlMartin1020-Jan-10 13:02 
AnswerRe: Display highlighted data from Listbox in Textboxes Pin
Luc Pattyn20-Jan-10 13:27
sitebuilderLuc Pattyn20-Jan-10 13:27 
GeneralRe: Display highlighted data from Listbox in Textboxes Pin
CarlMartin1020-Jan-10 13:31
CarlMartin1020-Jan-10 13:31 
GeneralRe: Display highlighted data from Listbox in Textboxes Pin
Luc Pattyn20-Jan-10 13:37
sitebuilderLuc Pattyn20-Jan-10 13:37 
AnswerRe: Display highlighted data from Listbox in Textboxes Pin
Anthony Mushrow20-Jan-10 13:34
professionalAnthony Mushrow20-Jan-10 13:34 
Instead of storing your contact data as an array of strings. You could create another class to contain all the data you need, and then use a list or array of that. For example:

class ContactData
{
  string FirstName;
  string LastName;
  string Address;
  string City;
  string State;
  string Zip;

  public override string ToString()
  {
    return FirstName + ", " + LastName;
  }
}


You could then add this class to your listbox just as you do with your current array of strings.

The override for ToString is so that the listbox knows what text to display for that item. So you can just do this when adding items (assuming Contacts is now an array of ContactData)

for (int j = 0; j < 20; j++)
{
  if (Contacts[j] != null)
  {
    lstContacts.Items.Add(Contacts[j]);
  }
}


Then, to get the information back out you can get the selected item from your listbox and cast it back to a ContactData and access your information:

private void lstContacts_SelectedIndexChanged(object sender, EventArgs e)
{
  ContactData myData = lstContacts.SelectedItem as ContactData; //myData will be null if SelectedItem is not actually ContactData
  tbxFirstName.Text = myData.FirstName;
  ...
}


My current favourite word is: Sammidge!
-SK Genius

Game Programming articles start -here[^]-

GeneralRe: Display highlighted data from Listbox in Textboxes Pin
CarlMartin1020-Jan-10 13:37
CarlMartin1020-Jan-10 13:37 
Questionuse of information from a previous form Pin
naghoumeh1420-Jan-10 10:22
naghoumeh1420-Jan-10 10:22 
AnswerRe: use of information from a previous form Pin
sanforjackass20-Jan-10 10:42
sanforjackass20-Jan-10 10:42 
GeneralRe: use of information from a previous form Pin
naghoumeh1420-Jan-10 10:54
naghoumeh1420-Jan-10 10:54 
AnswerRe: use of information from a previous form [modified] Pin
sanforjackass20-Jan-10 11:11
sanforjackass20-Jan-10 11:11 
AnswerRe: use of information from a previous form Pin
DaveyM6920-Jan-10 11:05
professionalDaveyM6920-Jan-10 11:05 
QuestionProblem with connection to Socket Pin
gottimukkala20-Jan-10 10:22
gottimukkala20-Jan-10 10:22 
AnswerRe: Problem with connection to Socket Pin
Rozis20-Jan-10 13:02
Rozis20-Jan-10 13:02 
AnswerRe: Problem with connection to Socket Pin
Abhinav S20-Jan-10 17:51
Abhinav S20-Jan-10 17:51 
Questionreading message by pop3 Pin
mohd_mogaly20-Jan-10 10:20
mohd_mogaly20-Jan-10 10:20 
AnswerRe: reading message by pop3 Pin
Rozis20-Jan-10 13:55
Rozis20-Jan-10 13:55 
QuestionXLinq question Pin
Jamie Nordmeyer20-Jan-10 10:18
Jamie Nordmeyer20-Jan-10 10:18 
QuestionConnecting windows application to a web server. [modified] Pin
amnewone20-Jan-10 7:58
amnewone20-Jan-10 7:58 
QuestionOpening a file Pin
Darrall20-Jan-10 7:03
Darrall20-Jan-10 7:03 
AnswerRe: Opening a file Pin
loyal ginger20-Jan-10 7:29
loyal ginger20-Jan-10 7:29 
GeneralRe: Opening a file Pin
Darrall20-Jan-10 7:36
Darrall20-Jan-10 7:36 
AnswerRe: Opening a file Pin
John Whitmire20-Jan-10 7:33
professionalJohn Whitmire20-Jan-10 7:33 

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.