Convert content of Textbox to string?

I'm trying to get the content of a Textbox into a ListView, and assume I'll have to convert it using ToString, but can't figure out the format. Can anyone show me how to do?

The Name of the Textbox is txtName:

privatevoid btnAddItem_Click(object sender,EventArgs e)

{

lvwListView.Items.Add(txtName);

}

[556 byte] By [zenzai] at [2007-12-24]
# 1

text is string - there is no need to convert it to string :)

what you have done is just fine but you need to add the .Text property to get the textual value:

this.lvwListView.Items.Add(txtName.Text);

ahmedilyas at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 2

Ah yes, of course!

Thanks!

zenzai at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 3
When I try the following

lstItems.Items.Add(txtAddItem.Text)

I get the txtAddItem.text underlined with the following tag message

Value of type 'String' cannot be converted to 'System.Windows.Forms.ListViewItem'.

Any idea what I did wrong?

Kevin.needs.help at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 4

thats correct as the overload for the Add() method is NOT expecting a string, instead you may need to do this:

this.lstItems.Items.Add(new ListViewItem(this.txtAddItem.Text));

ahmedilyas at 2007-10-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...