Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

textbox to listview

combobox

  • Please log in to reply
13 replies to this topic

#1 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 04 November 2008 - 07:50 AM

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

#2 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 04 November 2008 - 11:28 AM

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.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#3 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 04 November 2008 - 12:04 PM

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?
  • 0

#4 pb_ce85

pb_ce85

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 04 November 2008 - 01:00 PM

how do i add the data from the textbox to the listview by the column?


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

#5 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 04 November 2008 - 06:43 PM

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:
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.
  • 0

#6 pb_ce85

pb_ce85

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 04 November 2008 - 10:23 PM

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:
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:
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.
  • 0

#7 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 05 November 2008 - 08:06 AM

Hello pb,

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

#8 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 05 November 2008 - 08:18 AM

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?
  • 0

#9 pb_ce85

pb_ce85

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 05 November 2008 - 09:16 AM

Hi Siten0308,

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:
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;
                //...................
          }
     }
}

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!!!:confused:
You mean listView1? This is my list view.
For details about ListViewItem search it in MSDN.
Cheers.
  • 0

#10 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 05 November 2008 - 09:36 AM

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

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?
  • 0

#11 pb_ce85

pb_ce85

    CC Newcomer

  • Just Joined
  • PipPip
  • 21 posts

Posted 05 November 2008 - 09:47 AM

Do you really have a ListView control on your form? Do you mean DataGridView? Or what?
ListView is something like your windows desktop. You can put into it some icon-like items. What do you mean 2 doubles that user can add them? Can you explain more? I'm so confusing!!!:confused:
  • 0

#12 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 05 November 2008 - 09:57 AM

sorry need better explanation, for the columns it is quantity, description, value, and make/model, so i would have to say the double(type of variable) is going to be value and quantity(though i know no one would put a .1 for quantity). and the string of course would be description and make/model. hopefully that clears : )

Sorry last thing i want to add, the form 2 which has the textboxes, also has a button, so when the user clicks on the button, the textbox fields which have information are suppose to be populated in the correct columns, do i add the
listview1.items.add(lvi);

do I add that code into the button?
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download