Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- namespace PROG1
- {
- public partial class Form1 : Form
- {
- List<Clovek> seznam;
- static int i = 0;
- public Form1()
- {
- InitializeComponent();
- seznam = new List<Clovek>();
- listBox1.DataSource = seznam;
- listBox1.DisplayMember = "jmeno";
- }
- private void pridat(Clovek clovek)
- {
- seznam.Insert(i, clovek);
- i++;
- ((CurrencyManager)listBox1.BindingContext[seznam]).Refresh();
- }
- private void btnAdd_Click(object sender, EventArgs e)
- {
- Clovek c = new Clovek("Monika","Rousova",21);
- pridat(c);
- lblAge.Text = c.getVek().ToString();
- lblSurname.Text = c.getPrijmeni();
- }
- }
- class Clovek
- {
- private string jmeno;
- private string prijmeni;
- private int vek;
- public Clovek(string jmeno, string prijmeni, int vek)
- {
- this.jmeno = jmeno;
- this.prijmeni = prijmeni;
- this.vek = vek;
- }
- public Clovek(string jmeno)
- {
- this.jmeno = jmeno;
- }
- public string getJmeno()
- {
- return this.jmeno;
- }
- public void setJmeno(string jmeno)
- {
- this.jmeno = jmeno;
- }
- public string getPrijmeni()
- {
- return this.prijmeni;
- }
- public void setPrijmeni(string prijmeni)
- {
- this.prijmeni = prijmeni;
- }
- public int getVek()
- {
- return this.vek;
- }
- public void setVek(int vek)
- {
- this.vek = vek;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement