+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 14

Thread: textbox to listview

  1. #1
    Programming Professional Siten0308 will become famous soon enough Siten0308's Avatar
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    287

    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. #2
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    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

  3. #3
    Programming Professional Siten0308 will become famous soon enough Siten0308's Avatar
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    287

    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?

  4. #4
    Newbie pb_ce85 is an unknown quantity at this point pb_ce85's Avatar
    Join Date
    Jul 2008
    Posts
    21

    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 ...

  5. #5
    Programming Professional Siten0308 will become famous soon enough Siten0308's Avatar
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    287

    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.

  6. #6
    Newbie pb_ce85 is an unknown quantity at this point pb_ce85's Avatar
    Join Date
    Jul 2008
    Posts
    21

    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.

  7. #7
    Programming Professional Siten0308 will become famous soon enough Siten0308's Avatar
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    287

    Question Re: textbox to listview

    Hello pb,

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

  8. #8
    Programming Professional Siten0308 will become famous soon enough Siten0308's Avatar
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    287

    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?

  9. #9
    Newbie pb_ce85 is an unknown quantity at this point pb_ce85's Avatar
    Join Date
    Jul 2008
    Posts
    21

    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.

  10. #10
    Programming Professional Siten0308 will become famous soon enough Siten0308's Avatar
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    287

    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?

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Linking button to textbox
    By BrasilianBR in forum C and C++
    Replies: 21
    Last Post: 09-10-2008, 10:28 PM
  2. How to make a textbox not to show a specified number or letter ?
    By kresh7 in forum Visual Basic Programming
    Replies: 11
    Last Post: 02-28-2008, 11:04 AM
  3. Listview problems
    By wygz in forum Visual Basic Programming
    Replies: 2
    Last Post: 02-16-2008, 12:37 AM
  4. Hide and seek with a textbox character
    By dgates in forum JavaScript and CSS
    Replies: 0
    Last Post: 12-06-2007, 03:50 PM
  5. Hide and seek with a textbox character
    By dgates in forum C# Programming
    Replies: 1
    Last Post: 12-06-2007, 12:36 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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