Reputation: 103
So I have Form1
and Form2
. Form1
has listView1
inside which has 3 columns. Form2
has 3 textbox's which hold text. On Form2
there is a button to submit the text to the matching columns of Form1
.
How would I get this to happen?
This may not make sense and I will help make sense if that's the case.
Upvotes: 2
Views: 1071
Reputation: 2417
One approach would be to set up public properties for the text values in Form2
. When you submit the data you apply the textbox values to these properties, and then you can retrieve them from the Form2
object in Form1
. Here's an example:
Form2:
public string Name { get; set;}
private void buttonClick(object sender, EventArgs e)
{
Name = txtbxName.Text;
Close();
}
Form1:
var entryForm = new Form2();
entryForm.ShowDialog();
var text = entryForm.Name;
// Do whatever you want with `text`
EDIT: If you need help with inserting the data into the ListView
object I can give an example for that as well.
EDIT 2: Let's assume that you have three variables containing the values you want to add to the view: name
, age
, sex
. You should have some sort of unique ID value assigned to each record, so we'll also add an id
variable.
With those populated you can add a new record to your ListView
like so:
ListViewItem parent = listView1.Items.Add(id);
parent.SubItems.Add(name);
parent.SubItems.Add(age.ToString());
parent.SubItems.Add(sex);
Upvotes: 3
Reputation: 964
My suggestion would be
1) On button_click call form1.show(). 2) create another method which takes three textbox value and binds to listbox. For reference use this link for binding: C# listView, how do I add items to columns 2, 3 and 4 etc?
Upvotes: 0