NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


Stack Overflow

About
Products
For Teams

Join Stack Overflow to learn, share knowledge, and build your career.

Home
Public

Questions
Tags
Users
Find a Job
Jobs
Companies

Teams
Stack Overflow for Teams – Collaborate and share knowledge with a private group.

Adding stuff to listview from textbox
Asked 4 years, 10 months ago
Active 4 years, 10 months ago
Viewed 5k times
0

id like to know how to take one of my text boxs or strings and put it in a listview.. well not really let me show u wants going on.

i have a 2 text box with the following stuff

TextBox1

cat123
hatcat
quanwall
samiam12

TextBox2

John
will
sam
dan

i want to take TextBox1's text and put it in one of the columns in the ListView. for example. ListView has 2 columns saying usernames and realnames, and TextBox1 is the usernames and TextBox2 is the realnames. So i want to take each line in TextBox1 to match up with the RealNames(TextBox2) all in ListView.

iv bin using the

Dim Q As New ListViewItem
Q.Text = Host
Q.SubItems.Add(User)
Q.SubItems.Add(Pass)
ListView1.Items.Add(Q)

to add the strings to the listview

I need this information ASAP, Thx u <3
vb.net
Share
Improve this question
Follow
edited Jul 2 '16 at 2:38
asked Jul 2 '16 at 1:33
Zeltron playz
711 silver badge88 bronze badges
Add a comment
3 Answers
0

Try this (To listview1 put your listview name)

Dim i As Integer = 0
For Each l In TextBox1.Lines
ListView1.Items.Add(l)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(TextBox2.Lines(i))
i += 1
Next
i = 0

Share
Improve this answer
Follow
answered Jul 2 '16 at 17:15
BanForFun
64444 silver badges1515 bronze badges
Is this answer outdated?
Yes | No

thx man But i need to know how to add another subitem the same way, so its added to the next column. – Zeltron playz Jul 2 '16 at 18:39
From another textbox to a thrird column? – BanForFun Jul 4 '16 at 6:44
1
nvm i figured it out @BanForFun – Zeltron playz Jul 4 '16 at 6:57

Add a comment
0

While the straightforward answer to your question is rather simple, your posted question raises issues. You are using Listbox and Listview interchangeably, yet they are two different controls. Moreover you seem to suggest your Textbox holds multiple values where the intention of a Textbox is to hold one distinct value or string of text.

As these controls are Windows Forms controls, your use of "Dim Q As New ListviewItem" may not be neccessary.

I would suggest reading up more on the controls you want to use, how they are used and in what context.

The simple straightforward answer to your question could be:

listBox1.Items.Add(textBox1.Text)

For reference: How to: Add and Remove Items with the Windows Forms ListView Control
Share
Improve this answer
Follow
answered Jul 2 '16 at 2:22
Steve
50955 silver badges1717 bronze badges
Is this answer outdated?
Yes | No

Im sorry that u still do not under stand what i wanted to say, and no "YOUR STRAIGHT FOWERED Answer" did not help me. im also very sorry i wrote listbox ones in the begin of the text. Im Also VERy sorry that u dont understand that i didnt try to say that the text boxs have more values but to tell u that its on different lines. i wanted to take both of the text boxs and take the LINES of text and put them in different Columns IN the LISTVIEW. so there would have to be a code that separates the lines of text and adds the line of text as a row for the List view. – Zeltron playz Jul 2 '16 at 2:47

@Zeltronplayz : If you want to separate text, use String.Split(). – Visual Vincent Jul 2 '16 at 11:48

Add a comment
0

I'm assuming your user names are stored in TextBox1 and your real names are stored in TextBox2

Public Sub AddListViewItemsFromTextboxes()

Dim Host As String = "SomeHost" 'you mentioned a host in the code snippet in your question, not sure where this comes from

Dim TextBox1String As String = TextBox1.Text
Dim TextBox2String As String = TextBox2.Text

Dim TextBox1Lines() As String = TextBox1String.Split(vbNewLine)
Dim TextBox2Lines() As String = TextBox2String.Split(vbNewLine)

If(TextBox1Lines.Count <> TextBox2Lines.Count)
'possible error handling here
MsgBox("Each user must have both a real name and a username.")
Exit Sub
End If

For NameIndex As Integer = 0 to (TextBox1Lines.Count - 1)
Dim UserName As String = TextBox1Lines(NameIndex)
Dim RealName As String = TextBox2Lines(NameIndex)

Dim Item As New ListViewItem
Item.Text = Host

Dim UserNameSubItem As New ListViewitem.ListViewSubItem
UserNameSubItem.Text = UserName

Item.SubItems.Add(UserNameSubItem)

Dim RealNameSubItem As New ListViewItem.ListViewSubItem
RealNameSubItem.Text = RealName

Item.SubItems.Add(RealNameSubItem)

ListView1.Items.Add(Item)

Next

End Sub

Example GUI: http://i.stack.imgur.com/du95F.png

EDIT: Added third column
Share
Improve this answer
Follow
edited Jul 3 '16 at 23:54
answered Jul 3 '16 at 23:36
jrh
33522 gold badges88 silver badges2626 bronze badges
Is this answer outdated?
Yes | No

I'm not really sure if you want to display 2 columns of data or 3 columns in your listview, if you want 2 columns look at the previous version of my answer – jrh Jul 3 '16 at 23:50

Add a comment
Your Answer

Sign up or log in
Post as a guest
Name
Email

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
Not the answer you're looking for? Browse other questions tagged vb.net or ask your own question.

The Overflow Blog

Using Kubernetes to rethink your system architecture and ease technical debt

Level Up: Linear Regression in Python – Part 1
Featured on Meta
Testing three-vote close and reopen on 13 network sites
The future of Community Promotion, Open Source, and Hot Network Questions Ads
Outdated Accepted Answers: flagging exercise has begun

Top Hat
Top Hat
Education Technology
We have great benefits!
Catered Lunch
Best-in-class Equipment
Competitive Compensation
Free drinks
+ 4 more benefits
Learn more
Related
561
How do you get a string from a MemoryStream?
0
How can one extract/convert information from a Listview (to a DataTable)?
1
VB.NET How does one read a textbox into a string and use the string for something else?
1
Outputting 2 lists of data, but keeping them organised IN VB
1
How can I append a string that contains “” to an existing string in VB .NET?
0
invalidargument=value of '11' is not valid for 'index'
0
Any way to convert from Double to Hex in vb?
1
(Visual Basics and Excel) How to put a certain value into cell A2 if cell A1 has something in it
0
MySQL Query Browser Error Data truncated for column
Hot Network Questions

Meaning of "She had all the colour and dynamism of a parsnip"
Layout-preserving converter from beamer PDF to powerpoint
Why would the gods be labelled?
Could a ghost Parselmouth open the Chamber of Secrets?
To what extent should an (almost) two year old be able to lie still on command?
Getting all data of my JSON object from Serial.read() at once
Count how many arguments passed as positional
trying to find the title of this time travel book
Simplifying polygon by inner angle
Make a polyglot generator
Why did it take a millennium to use harmony/polyphony (900 AD) when Pythagoras discovered perfect fourth and fifth around 500 BC?
What's the bijection between reals and infinite sequences of integers?
Convince me Gabriel's Horn is possible
How do I brew french roast coffee, so that it doesn' taste like ash
Agile in a reactive organisation?
Why would a matriarchal society practice polygyny?
Is it a good idea to hand sew a denim pencil skirt with false cuts instead of using sewing machine?
Does going faster always result in more calories burnt
"must" vs "shall" - are they the same, or is one a softened version of the other?
Hydrogen burning vs Hydrogen fusing
Precise skills connected with rating value
retsubkcolB Spelled Backwards
How to determine that a single transistor is NPN or PNP
Why is process object is shown as desktop object in nt!_object_type

Question feed

Stack Overflow

Questions
Jobs
Developer Jobs Directory
Salary Calculator
Help
Mobile
Disable Responsiveness

Products

Teams
Talent
Advertising
Enterprise

Company

About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us
Cookie Settings
Cookie Policy

Stack Exchange
Network

Technology
Life / Arts
Culture / Recreation
Science
Other

Blog
Facebook
Twitter
LinkedIn
Instagram

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.5.20.39353
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.