Hi I need some help about C#
I know it is elementary but I don't know how to do that. and also I works without database
I have class User with
string name;
string lastname;
int years;
and then a metod insert ()
{
User us=new User();
name=textbox1.Text;
lastname=textbox2.Text;
years=textbox3.Text;
}
Now for example I need to add(insert) tree(3) users and then write them in listbox, message box or something.
I hope I was clear enough and correctly ask the question
(How to read all instaces of the same class and also I need to sort them by year)
VulpesPosted Sep 12, 2014, 10:09 AM
Are you sure that there is something in the texboxes when you click the button?
Also did you remember to add the button_Click event handler via the VS designer rather than manually?
Boguda BogudaPosted Sep 12, 2014, 5:50 AM
VulpesPosted Sep 11, 2014, 5:42 PM
I added two to start with and additional users can then be added by filling in the TextBoxes and pressing the button.
As you said that the users needed to be sorted by 'years', I assumed that you wanted the whole record to be shown in the listbox. By overriding the ToString method in the User class, we can layout exactly how each record should be displayed so that the properties line up.
Boguda BogudaPosted Sep 11, 2014, 7:03 AM
Boguda BogudaPosted Sep 11, 2014, 5:11 AM
Nitesh KejriwalPosted Sep 10, 2014, 10:35 PM
VulpesPosted Sep 10, 2014, 7:52 PM
You'll need to set the ListBox's Font property to a fixed width font (such as Consolas) so that the properties line up properly.
I've added two User objects to the ListBox in Form1_Load and you can then add a third (or as many others as you like) by filling out the 3 textboxes and then pressing the button to insert them. They will be automatically sorted by 'years':