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]
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);
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?
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));