Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: textbox to listview

  1. #1
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question textbox to listview

    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.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: textbox to listview

    Create a new instance of the data form with the "new" keyword. After you show it with ShowDialog(), you should be able to access its properties straight from the instance object.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  4. #3
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question Re: textbox to listview

    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?

  5. #4
    pb_ce85's Avatar
    pb_ce85 is offline Newbie
    Join Date
    Jul 2008
    Posts
    21
    Rep Power
    0

    Re: textbox to listview

    Quote Originally Posted by Siten0308 View Post
    how do i add the data from the textbox to the listview by the column?
    Code:
    string[] items = {"Item", "subItem1", "subItem2" /*, ... */};
    ListViewItem lvi = new ListViewItem(items);
    listView1.Items.Add(lvi);
    "Item" goes to first column, "subItem1" is in 2nd column, "subItem2" in 3rd and ...

  6. #5
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question Re: textbox to listview

    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:
    Code:
    string[] items = {"Item", "subItem1", "subItem2" /*, ... */};
    ListViewItem lvi = new ListViewItem(items);
    listView1.Items.Add(lvi);
    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?
    i would assume it is something like the above example but can you let me know? thanks again for your guys help.

  7. #6
    pb_ce85's Avatar
    pb_ce85 is offline Newbie
    Join Date
    Jul 2008
    Posts
    21
    Rep Power
    0

    Re: textbox to listview

    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:
    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.
              }
         }
    }
    And you can access PUBLIC fields, everywhere you want by create an instance from its owner.
    Now assume you have another form named 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);
              }
         }
    }
    Look at f2.textField. You filled it in form2 from your textBoxes, and you're using it in form1.

  8. #7
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question Re: textbox to listview

    Hello pb,

    Thanks for the info, that clears up some questions, but what happens when i have multiple textboxes?

  9. #8
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Re: textbox to listview

    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?

  10. #9
    pb_ce85's Avatar
    pb_ce85 is offline Newbie
    Join Date
    Jul 2008
    Posts
    21
    Rep Power
    0

    Re: textbox to listview

    Hi Siten0308,
    Quote Originally Posted by Siten0308 View Post
    Hello pb,

    but what happens when i have multiple textboxes?
    Well, you have no limitation in declaring fields. each textBox can have a field.
    In this case you have:
    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;
                    //...................
              }
         }
    }
    Quote Originally Posted by Siten0308 View Post
    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?
    I haven't any listviewitem1!!!
    You mean listView1? This is my list view.
    For details about ListViewItem search it in MSDN.
    Cheers.

  11. #10
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question Re: textbox to listview

    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

    Code:
    string[] items = {f2.textField, "subItem1", "subItem2" /*, ... */};
    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?

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Listview Help?????
    By jbnonn in forum C# Programming
    Replies: 3
    Last Post: 01-30-2011, 02:17 PM
  2. can fix it about listview
    By kiddies in forum Visual Basic Programming
    Replies: 2
    Last Post: 06-22-2010, 03:57 AM
  3. Help Using Listview
    By edge02 in forum Visual Basic Programming
    Replies: 2
    Last Post: 04-04-2010, 12:58 AM
  4. listview
    By Siten0308 in forum C# Programming
    Replies: 13
    Last Post: 12-12-2008, 09:14 AM
  5. ListView Help?
    By MXTECH in forum Visual Basic Programming
    Replies: 3
    Last Post: 11-17-2008, 12:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts