combobox hlp

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
15 posts Page 1 of 2
Contributors
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

combobox hlp
Shim
hello programmer(s)

<!--- shim need your help -->

i have a combobox and i want to load a textfile hosted on my host and also the texts should be organized
Find my programs on Softpedia
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

Re: combobox hlp
noypikami
can you explain further? please! may be i can help.
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: combobox hlp
muttley1968
If im thinking you want it like a sorta multiple choice system deal then you best bet would be to format the text into a listbox
and then populate that into the combobox alot easier that way and not to big of a code job :)
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: combobox hlp
smashapps
First off you can sort all items of a combox box by setting its SORTING property to TRUE.

You will need to download the text file, read it line by line and then add them by using AddRange and read all lines of the text file
Code: Select all
Imports System.IO

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            'First off we need to downlaod the text file
            My.Computer.Network.DownloadFile("http://pastebin.com/raw.php?i=xX9sSc7K", Application.StartupPath & "/text.txt", "", "", True, 100, True)
            'here we download the file, set user and pass to default and we show the ui of the progress, 100 second timeout and we want to override the 
            'file if it exists already if it exists already so we have an updated version each time


            'now we will read the text file and add items to comboxbox
            ComboBox1.Items.AddRange(File.ReadAllLines(Application.StartupPath & "/text.txt"))
        Catch ex As Exception
            MsgBox("Error" & vbNewLine & ex.Message)
        End Try

       
    End Sub
End Class
For this you will need a combobox thats it. I wrote this example myself and I set the link to a pastebin file, just change it the link of your text file. It should be easy to understand, we download the text file and save it in the programs startup location, we read all lines of the text file and then add them to the combox, to sort the items we set the sorting property to true.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: combobox hlp
Shim
i dont want to download the file and read it i just want to do this
Code: Select all
 Dim client As WebClient
        Dim shim As String = client.DownloadString("http://website.com/file.txt")
        ComboBox1.Items.Add(shim)
Find my programs on Softpedia
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: combobox hlp
smashapps
Did you still need help? Your code there will have everything in that one file added as one item

I am not particularly sure what you want out of this. If you didn't want the file to be store on the computer you can always use
Code: Select all
My.Computer.FileSystem.DeleteFile("")
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: combobox hlp
Shim
no when i use my code the text all mess in the combo
Find my programs on Softpedia
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

Re: combobox hlp
visualtech
Try This:

Dim r As IO.StreamReader

r = New IO.StreamReader("Path To Your File")
While (r.Peek() > -1)
ComboBox1.Items.Add(r.ReadLine)
End While
r.Close()
Image
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: combobox hlp
muttley1968
Is it possible for you to tell is what you are wanting this code to do and also giving us a link to the file so we can attempt to code up wat you want
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: combobox hlp
Shim
visualtech wrote:
Try This:

Dim r As IO.StreamReader

r = New IO.StreamReader("Path To Your File")
While (r.Peek() > -1)
ComboBox1.Items.Add(r.ReadLine)
End While
r.Close()
thanks but its on internet
Find my programs on Softpedia
15 posts Page 1 of 2
Return to “Coding Help & Support”