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

C#

 
QuestionProblem with AutoResetEvent Array and WaitHandle.WaitAll() Pin
FJJCENTU20-Jan-10 13:27
FJJCENTU20-Jan-10 13:27 
AnswerRe: Problem with AutoResetEvent Array and WaitHandle.WaitAll() Pin
Bekjong20-Jan-10 15:50
Bekjong20-Jan-10 15:50 
AnswerRe: Problem with AutoResetEvent Array and WaitHandle.WaitAll() Pin
Giorgi Dalakishvili20-Jan-10 19:17
mentorGiorgi Dalakishvili20-Jan-10 19:17 
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 
Hi,

I have a lot of comments, here are some:

1.
you should not try and keep a lot of information in a single string, so string[] Contacts isn't a good choice.

2.
you should also not try and keep an unknown number of items in an array, as that will become a functional limitation, and needs code to guard you against an overflow. Instead use some kind of list; ArrayList is simple, however it got superceded by List<sometype> which is known as a generic list.

3.
a ListBox can hold items of any kind you choose, not just strings. So what you could and should do is:
- declare a Contact class, with all the fields you like;
- create, then add, such Contact instances to the ListBox;
- to get it painted, do one of these:
   a) give Contact a ToString() method that lists all fields, each with a constant width (i.e. use string.PadRight() or string.PadLeft() to add spaces;
   b) make the ListBox ownerdrawn, and provide a DrawItem handler which basically does a Graphics.DrawString() for each of the fields.

4.
If you want to be able to sort your contacts on each of the fields, then you would be better of with a DataGridView

5.
some comments on coding style:
- don't call ToString() on strings, as it doesn't achieve anything (see Contacts[j].ToString())
- don't use short identifiers for class members (your int i); a one-letter identifier is OK for a local for loop, not for a state variable.
- don't create empty catch blocks; always specify what it is you catch, and then show it, so no problem can go unnoticed and waste hours of debugging. Example:
try {
    ...
} catch(Exception exc) {
    MessageBox.Show(exc.ToString());
}


6.
and finally, if you haven't done so yet, buy and study a book on C#, it introduces you to all major language features and good coding practices.

Smile | :)

Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]


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 
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 

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.