473,378 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Adding .txt File into Listbox

Well, Im wondering how i can do this:
I have a load button and a listbox.

When i click The Load Button you select a .txt file to load into the Listbox, Thanks :)

VB.NET Btw
Nov 2 '07 #1
2 1649
debasisdas
8,127 Expert 4TB
What does the textfile contains ?

Why you need to add the containt of txt file to listbox it can be easily loaded to any textbox.
Nov 2 '07 #2
balabaster
797 Expert 512MB
Well, Im wondering how i can do this:
I have a load button and a listbox.

When i click The Load Button you select a .txt file to load into the Listbox, Thanks :)

VB.NET Btw
I'm assuming that you are going to be holding the contents of the list box in the text file so that you can modify this without modifying your code and recompiling. It really depends on the format of your file...for instance, is it XML, plaintext or some other format. Assuming the file is just plain text and that the file holds one listbox entry per line:

Expand|Select|Wrap|Line Numbers
  1. Dim oText As System.IO.StreamReader = Nothing
  2. Try
  3.     oText = System.IO.File.OpenText("C:\MyList.txt")
  4.     While Not oText.EndOfStream
  5.         Dim sCurrentLine As String = oText.ReadLine
  6.         ListBox1.Items.Add(sCurrentLine)
  7.     End While
  8. Catch ex As Exception
  9.     MsgBox(ex.Message)
  10. Finally
  11.     If Not oText Is Nothing Then
  12.         oText.Close()
  13.         oText.Dispose()
  14.     End If
  15. End Try
Obviously you wouldn't hard code the name of the file as that's pretty bad coding practice...you'd likely load the name from a settings file, but that should give you an idea of how to load the content of a text file into a list box.
Nov 2 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John R. | last post by:
I want to have a listbox that shows a checkbox and a textbox. I created a user control that has a checkbox and a textbox in it and have been trying to add it to a listbox but I can't get it to...
3
by: Ryan Taylor | last post by:
Hello. I have an application where I need the user to be able to add items to a listbox. I've implemented this via javascript. The listbox is an <asp:ListBox>. However, when the user submits the...
3
by: Husam | last post by:
Hi EveryBody: I made project by Vb.Net which consist the following items: 1\ Textbox 2\Button 3\Listbox When you write any thing in the textbox and press the button any text written in...
6
by: Papa.Coen | last post by:
I've just spend a lot of time solving the following problem: I used dotNet 2.0 / Visualstudio 2005 / C# / aspx, enable viewstate is set on all controls. I have 2 listboxes; the left contains items...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
1
by: bill | last post by:
I need to be able to dynamically add items to a <asp:listbox> (or HTML <select runat=server>) using clientside javascript, and retrieve the items when the page is posted back. I use this code to...
0
by: spowel4 | last post by:
VB 2005: Using an xml file as the data source, I need to fill a listbox with data based upon what was selected in a combobox. In other words, my data consists of a list of customers in a...
2
by: =?Utf-8?B?TWFobW91ZCBTaGFiYW4=?= | last post by:
i have a problem in adding new listbox items i don't need to allow adding multible items with the same textvalue ex: if current items are: green red
4
by: ranjini ns | last post by:
Hi, I have a form, and in this form, there are 2 drop down list a text box, one button (labelled "add" )and finally, a listbox. The question is, when the user clicks on the add button, how do I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.