I'm pretty new to C# and trying to make a method on how to change the name, address, etc. in a listview addressbook.
Have been scratching my head for a while on how to make the ".Name" part into a variable that can be passed through to the method as a parameter.
For my method to work, i need to be able to change the ".Name" part to: ".Address", ".Phone" and so on using parameters.
Box1 represents textboxes that are disabled and only show information about the selected item in the list view. Box2 represent the box in where the user can type the changes he wants to make.
The code is working, this is just to learn how to be more efficient and not duplicate.
private void CheckInput(string box1, string box2, string details)
{
if (box2 != box1 && box2 != "")
{
DialogResult dialogResult = MessageBox.Show(
"Are you sure you want to change the " + details
+ " from, " + box1 + ", to, " + box2 + "?", "Warning",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes)
{
people[listView1.SelectedItems[0].Index].Name = box2;
if (box2 == "")
{
listView1.SelectedItems[0].Text = box1;
}
else
{
listView1.SelectedItems[0].Text = box2;
}
}
if (dialogResult == DialogResult.No)
{
}
}
}
class Person
{
public string Name
{
get;
set;
}
public string Email
{
get;
set;
}
public string Address
{
get;
set;
}
public string Phone
{
get;
set;
}
}