Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello,
 
I need your help, if it is possibe.
 
I need to check if already exists a employer in the list with same code entered in the textbox.
 
I have a list of employers, and I add employers like this :
else if (cb_type.Text == type1.text)
{
 
     type1 typeone = new typeone(Convert.ToInt32(tb_Code.Text), tb_Name.Text, Convert.ToDateTime(dateTimePicker1.Text), cb_Sex.Text, tb_Adress.Text, Convert.ToInt32(tb_Phone.Text), tb_Email.Text, pictureBox1.Image);
     LEmployer.Add(typeone);
     listBox1.Items.Add(V.getName());
     listBox1.Show();
}
In the moment that i add a new employer i need to verify if already exists a employer with the same code that is entered in textbox.
 
I try this :
foreach (employer E in Lemployer)
{
      if tb_code.text == E.getCode())
      {
           Messagebox.show("Code Already exists");
      }
}
But this isn't working, someone can help me doing this?
 
Thanks
Posted 27-Jan-13 13:10pm
mibetty480
v2
Comments
PIEBALDconsult at 27-Jan-13 19:53pm
   
First off, please use proper Parse or TryParse methods rather than Convert.
Second, please use proper controls for what you need rather than TextBoxes for everything.
What does getCode do?
mibetty at 27-Jan-13 21:02pm
   
thank for your answer,
 
getCode is a method in the employer class, like this :
 
public int getCode()
{
return Code;
}
Sergey Alexandrovich Kryukov at 27-Jan-13 21:52pm
   
It should be a property with getter.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

but if i use a sortedlist i need to change all code right? :/
  Permalink  
Comments
Tadit Dash at 28-Jan-13 9:14am
   
Please add this as a comment, not here as an answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 350
1 Sergey Alexandrovich Kryukov 320
2 BillWoodruff 309
3 George Jonsson 274
4 OriginalGriff 237
0 OriginalGriff 4,903
1 CPallini 3,960
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,786
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100