Reputation: 39
Hello i need help adding items to my listview im using this:
private void btnSubmit_Click(object sender, EventArgs e)
{
Person newPerson = new Person()
{
Name = txtName.Text,
Age = txtAge.Text,
Gender = txtGender.Text,
Photo = txtPhoto.Text
};
string[] row = { txtName.Text, txtAge.Text, txtGender.Text, txtPhoto.Text};
ListViewItem item = new ListViewItem(row);
lvPersons.Items.Add(item);
}
This is working but i want to use my class person to add and not this line:
string[] row = { txtName.Text, txtAge.Text, txtGender.Text, txtPhoto.Text};
because using the line above im not making use of this: (i think)
Person newPerson = new Person()
{
Name = txtName.Text,
Age = txtAge.Text,
Gender = txtGender.Text,
Photo = txtPhoto.Text
};
Can someone help me adding items with my class i have tested with this:
string[] row = { Name, Age, Gender, Photo };
and this
string[] row = {Person Name, Person Age, Person Gender, Person Photo };
but both give me errors i need some help
Upvotes: 1
Views: 132
Reputation: 39
It's working with:
ListViewItem item = new ListViewItem(new [] {newPerson.Name, newPerson.Age, newPerson.Gender, newPerson.Photo});
Thanks to @René Vogt for the help/solution.
Upvotes: 1
Reputation: 1530
try this,
string[] row = { "1000", "2000", "3000", "4000" };
List<string> lvPersons = new List<string>();
foreach (var item in row)
{
lvPersons.Add(item);
}
Upvotes: 0