ListBox Help

Do you need something made? then ask 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.
16 posts Page 1 of 2
Contributors
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 am

ListBox Help
harmeister
Ok just picture this with me, I know I don't have the proper skills to make this, but view it from text as you will.
I have a listbox and I want to make it look like this:
Page Title Column | Url Column
Msn.com | http://www.msn.com







____________________________________
Add Button | Delete Button | Delete All Button

How do I make it look like that and when I hit the add button it adds the page title and the url at the same time on the same line and when I hit delete it deletes only the one selected item and leaves the rest of the titles and urls alone, and when I hit the delete all button everthing is gone?
Sincerely,
Harley
[Information Technologist in training, New to the whole VB coding]
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: ListBox Help
mandai
Listboxes aren't great for columns. Consider using a ListView instead.

Though you could try what has been posted here: viewtopic.php?f=32&t=2475&p=15896#p15896
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 am

Re: ListBox Help
harmeister
Now using this will I be able to select one part like either the url or the name and it will delete the whole thing?
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 am

Re: ListBox Help
harmeister
Oh wait I see what you are saying so how do I make the columns for this and how do I make this work?
Sincerely,
Harley
[Information Technologist in training, New to the whole VB coding]
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: ListBox Help
mandai
There is an example of how to add/access the values in that thread.
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 am

Re: ListBox Help
harmeister
oh really? is it for listbox or listview?
Sincerely,
Harley
[Information Technologist in training, New to the whole VB coding]
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: ListBox Help
mandai
That is for listbox.

This is the way to do it with a listview:
Code: Select all
        ListView1.View = View.Details
        ListView1.Columns.Add("column1")
        ListView1.Columns.Add("column2")
        ListView1.Items.Add(New ListViewItem(New String() {"value1", "value2"}))
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 am

Re: ListBox Help
harmeister
mandai wrote:
That is for listbox.

This is the way to do it with a listview:
Code: Select all
        ListView1.View = View.Details
        ListView1.Columns.Add("column1")
        ListView1.Columns.Add("column2")
        ListView1.Items.Add(New ListViewItem(New String() {"value1", "value2"}))
Ok I get the first three lines, but what are the strings for? can't I just add the items in the colums? I also have another question, sorry if I took so long for a reply, but I was out camping for a few days and I had a great time, since this is for bookmarks and I am using a listview how can I make it to where they both are in the same string in the settings or do I have to make seperate strings for the items?
Sincerely,
Harley
[Information Technologist in training, New to the whole VB coding]
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: ListBox Help
mandai
The string array in the 4th line is an example, it has to be an array so the listviewitem knows which column each value belongs in. There is no other way to do that.

You could have a bookmark name as one value and the url as another value, then you access it with Items(x).SubItems(y).Text - where x is the listview item index and y is whether you want to get the name or the url value.
User avatar
harmeister
VIP - Donator
VIP - Donator
Posts: 26
Joined: Fri Jul 23, 2010 1:21 am

Re: ListBox Help
harmeister
Ok just another question.
Code: Select all
Dim i As Integer = lstBookmarks.SelectedIndex

        lstBookmarks.Items.RemoveAt(i)
        My.Settings.Bookmarks_Menu.RemoveAt(i)
The codes above is what I am using now for my bookmarks in the listbox how can I transfer this into listview codes so it still has the same effect because when people right click on the selected item they can click remove and it removes the bookmark from the box and the settings without changing anything else.


I am sorry I wasn't clear enough let me add some more details.
This is what I am trying to do.....
Code: Select all
Dim i As Integer = listview1.SelectedIndex

        listview1.Items.RemoveAt(i)
        My.Settings.Bookmarks.RemoveAt(i)
And for some reason it isn't working. The whole dim thing well after the = sign it is underlined in blue. How do I change that so it will work and I don't know if I have to put a code in there to remove the item in both columns or will remove both from the code up there?

Also you see this code?
Code: Select all
        My.Settings.Bookmarks.Add(ComboBox1.Text)
        ListBox1.Items.Clear()
        For Each Item As String In My.Settings.Bookmarks
            ListBox1.Items.Add(Item)
        Next
        My.Settings.BKDocTitle.Add(CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle)
        ListBox3.Items.Clear()
        For Each item As String In My.Settings.BKDocTitle
            ListBox3.Items.Add(item)
        Next
This code add the bookmarks, and my setup is to listboxes. One listbox that has the page name and the other listbox has the url, with that code up there how can I alter that for the two colums I made called Page Name and URL?
Sincerely,
Harley
[Information Technologist in training, New to the whole VB coding]
16 posts Page 1 of 2
Return to “Tutorial Requests”