I have two TextBoxes: the first one is Firstname and the other is Lastname. I can get the values from the firstName TextBox but not the lastName TextBox.
The TextBoxes are inside CustomerFrame class.
if (customerframe.ShowDialog() == DialogResult.OK)
{
listView1.Items.Add("[{0}, {1}]", customerframe.firstName, customerframe.lastName);
}
Here is the CustomerFrame class:
private void btnOk_Click(object sender, EventArgs e)
{
firstName = tbFirstName.Text;
lastName = tbLastName.Text;
}
In the ListView only the letters from the firstName appears. Whats wrong?
Basically, you forgot to write
string.Format. The code should readThe way the code is written right now, it calls this overload of the
Addmethod by mistake, when you were intending to call this overload instead.In the overload you do end up calling (with the three parameters), the second parameter is the item text — what will be displayed. That’s why only the
firstNameshows in the list.