Page 1 of 2

ListBox Help

Posted: Wed Jul 28, 2010 5:30 am
by 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?

Re: ListBox Help

Posted: Wed Jul 28, 2010 10:29 am
by 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

Re: ListBox Help

Posted: Wed Jul 28, 2010 5:37 pm
by 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?

Re: ListBox Help

Posted: Wed Jul 28, 2010 11:31 pm
by 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?

Re: ListBox Help

Posted: Thu Jul 29, 2010 12:39 am
by mandai
There is an example of how to add/access the values in that thread.

Re: ListBox Help

Posted: Thu Jul 29, 2010 3:26 am
by harmeister
oh really? is it for listbox or listview?

Re: ListBox Help

Posted: Thu Jul 29, 2010 5:20 pm
by 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"}))

Re: ListBox Help

Posted: Tue Aug 03, 2010 7:01 pm
by 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?

Re: ListBox Help

Posted: Tue Aug 03, 2010 9:10 pm
by 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.

Re: ListBox Help

Posted: Wed Aug 04, 2010 11:19 pm
by 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?