Hello,
ok sorry for the last post, you can delete it if you want, i just thought maybe someone might find that beneficial, i know i did. Anyways on with the question.
i have a main form, that has a listview on it with of course headers such as make, model, description, etc. i have a combobox that if click add new item, it opens up a new form that gives you textboxes to import data, once click on the submit button on that add form, it imports the information from the text boxes to the listview. How do i go about doing that?
Thanks again in advance.
Hello Xav,
thanks for the info but i am still a little confused, can you give a little more information sorry. also how do i add the data from the textbox to the listview by the column?
Hello pb
Thanks for the info, but i am just wondering for the sac of example, again i am still sadly new, but since i would make a new instance we will say form 1 has listview and form 2 has the textboxes. now for form1 i would obviously create new instance such as form1 formof1 = new form1(), then i would then be able to double click submit button and go in and from there put in the following:
but how do i get the text boxes lets say again for the example, form2 is with the textbox name, and i want textbox name to show up in the listview under column name. how would i go about doing that?Code:string[] items = {"Item", "subItem1", "subItem2" /*, ... */}; ListViewItem lvi = new ListViewItem(items); listView1.Items.Add(lvi);
i would assume it is something like the above example but can you let me know? thanks again for your guys help.
Hello,
Xav said that before, but let me show you an example.
Do you know anything about fields?
OK, let me explain.
Assume you have a form named form2:
And you can access PUBLIC fields, everywhere you want by create an instance from its owner.Code:namespace Test { public partial class form2 : Form { public string textField; // This is a Field. public form1() // Here's your constructor. { InitializeComponenets(); } private void SetField() { this.textField = textBox1.Text; // You're filling your textField Field here. } } }
Now assume you have another form named form1:
Look at f2.textField. You filled it in form2 from your textBoxes, and you're using it in form1.Code:namespace Test { public partial class form1 : Form { public form1() { InitializeComponents(); } private void fillListView() { form2 f2 = new form2(); f2.ShowDialog(); string[] items = {f2.textField, "subItem1", "subItem2" /*, ... */}; ListViewItem lvi = new ListViewItem(items); listView1.Items.Add(lvi); } } }
Hello pb,
Thanks for the info, that clears up some questions, but what happens when i have multiple textboxes?
Hey pb,
I also having a question regarding your example:
what is listviewitem1 and what is the listviewitem? i assume listviewitem is the class delcared as lvi right?
Hi Siten0308,
Well, you have no limitation in declaring fields. each textBox can have a field.
In this case you have:
I haven't any listviewitem1!!!Code:namespace Test { public partial class form2 : Form { public string textField; // This is a Field. public string textField2; // Here's another Field. //........ public form1() // Here's your constructor. { InitializeComponenets(); } private void SetField() { this.textField = textBox1.Text; // You're filling your textField Field here. this.textField2 = textBox2.Text; //................... } } }
You mean listView1? This is my list view.
For details about ListViewItem search it in MSDN.
Cheers.
Hello Pb,
thanks again, i think its going to work, but sadly some of my columns are not all string, so for the part that is
i have 2 that are double, which i would like them to be so when the person decides to add them together, i can just write a simple method on that. but what should i do?Code:string[] items = {f2.textField, "subItem1", "subItem2" /*, ... */};
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks