Zdravím, som v programovaní začiatočník. Vedel by mi niekto teda pomôcť s presunom textu z "colection" do listboxu? Tymto sposobom, ako som uviedol dole, sa mi vzdy ukaze iba NAME ale SURNAME nikdy ... a nieviem preco ....
p.s. sorry za trocha dlhsi kod
class MyClass
{
public struct Person
{
public string Name { get; set; }
public string Surname { get; set; }
private int age;
public int Age
{
set { age = value; }
get { return age; }
}
}
List<Person> clientCollection = new List<Person>(10);
public bool setCollection(string namePerson, string surnamePerson, int agePerson)
{
try
{
Person client = new Person();
client.Name = namePerson;
client.Surname = surnamePerson;
client.Age = agePerson;
clientCollection.Add(client);
return true;
}
catch
{
return false;
}
}
public List<Person> returnColection()
{
return clientCollection;
}
}
Form:
private MyClass friend = new MyClass();
private void button1_Click(object sender, EventArgs e)
{
try
{
string namePerson = txtName.Text;
string surnamePerson = txtSurname.Text;
int agePerson = Convert.ToInt32(txtAge.Text);
if(friend.setCollection(namePerson, surnamePerson, agePerson)==false)
{
}
}
catch
{
}
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.DataSource = null;
listBox1.DisplayMember = "Name";
listBox1.DisplayMember = "Surname";
listBox1.ValueMember = "Age";
listBox1.DataSource = friend.returnColection();
}