|
-
Apr 4th, 2008, 08:49 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005]trying to create a custom string
Hi to all,
In my application i have a listbox, with a a webbrowser
i would like to create an string or an object whichever way i can do it, something that has a Name that will be the webbrowser1.docuenttitle and a value that will be the webbbrowser1.url.tostring
i have an idea of how it could be, but i dont know how to start it :
Code:
public class CustomObject
dim s as string
public property Name
get
return s
'etc........
dim s1 as string
public property Url
Get
return s1
'etc.....
end class
and then to add the object
Code:
dim s as new CustomObject
s.name=webbrowser1.documenttitle
s.url=webbrowser1.url.tostring
listbox1.items.add(s)
it could be something like that but im not really sure.....if someone could help me it would be really nice......
-
Apr 4th, 2008, 09:45 PM
#2
Re: [2005]trying to create a custom string
vb.net Code:
Public Class WebPageInfo Private _title As String Private _url As String Public Property Title() As String Get Return Me._title End Get Set(ByVal value As String) Me._title = value End Set End Property Public Property Url() As String Get Return Me._url End Get Set(ByVal value As String) Me._url = value End Set End Property Public Sub New(ByVal title As String, ByVal url As String) Me._title = title Me._url = url End Sub End Class
vb.net Code:
Public Class Form1 Private pageInfos As New System.ComponentModel.BindingList(Of WebPageInfo) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.BindingSource1.DataSource = Me.pageInfos Me.ListBox1.DisplayMember = "Title" Me.ListBox1.ValueMember = "Url" Me.ListBox1.DataSource = Me.BindingSource1 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.pageInfos.Add(New WebPageInfo(Me.WebBrowser1.DocumentTitle, _ Me.WebBrowser1.Url.ToString())) End Sub End Class
By using a BindingList and binding it to the control, each time you add or remove an item in the list the control will update automatically. By setting the DisplayMember you tell the control to display the Title property values. By setting the ValueMember you make the Url property value of the SelectedItem available via the SelectedValue.
-
Apr 4th, 2008, 09:49 PM
#3
Thread Starter
Hyperactive Member
Re: [2005]trying to create a custom string
-
Apr 5th, 2008, 09:09 AM
#4
Thread Starter
Hyperactive Member
Re: [RESOLVED] [2005]trying to create a custom string
jmcilhinney, i have my code working it works great, but i would like to create a function that allows to add the item only Once, i think i have to use listbox1.findstring() method but im not sure, and if i have to use that method what string do i have to search for ? pageinfos.tostring ?
thanks
-
Apr 5th, 2008, 09:45 AM
#5
Re: [RESOLVED] [2005]trying to create a custom string
ListBox.FindString finds the first item in the ListBox where the displayed text starts with the specified value. For each WebPageInfo object you add to the list, what value is displayed in the ListBox? It's not the result of the ToString method.
-
Apr 5th, 2008, 10:12 AM
#6
Thread Starter
Hyperactive Member
Re: [RESOLVED] [2005]trying to create a custom string
So, what method could i use ?
-
Apr 5th, 2008, 06:32 PM
#7
Re: [RESOLVED] [2005]trying to create a custom string
What did I say?
ListBox.FindString finds the first item in the ListBox where the displayed text starts with the specified value. For each WebPageInfo object you add to the list, what value is displayed in the ListBox?
Did you answer that question? I'll give you a clue:
Code:
Me.ListBox1.DisplayMember = "Title"
-
Apr 5th, 2008, 09:20 PM
#8
Thread Starter
Hyperactive Member
Re: [RESOLVED] [2005]trying to create a custom string
jmcilhinney, the code i have so far its this :
Dim s As Object
For Each s In Me.pageinfos
Dim n As Integer = ListBox1.FindString(ListBox1.DisplayMember)
If (n = -1) Then
Me.pageinfos.Add(New WebPageInfo(WebBrowser1.DocumentTitle, WebBrowser1.Url.ToString))
End If
Next
thats what i have, but apparently it doesnt works......i appreciate your help, it would be nice if u give me another clue, im trying to code everything by myself...
-
Apr 5th, 2008, 09:26 PM
#9
Re: [RESOLVED] [2005]trying to create a custom string
When you set the DisplayMember to "Title" you're telling the control to display the Title property value of each item. If FindString finds the first matching displayed value and the displayed values are the Title properties, what value do you think you have to pass to FindString?
That said, it's probably the URL that is of more interest than the title. In that case you wouldn't use FindString but rather just loop through the list and compare each URL value. Alternatively you could maintain a separate Dictionary for fast lookups.
Also, if you're going to ask more questions can you not resolve the thread? If a thread is resolved then don't keep posting to it. Start a new thread for a new question. If the thread is not resolved then don't mark it resolved or unresolve it. The ability to unresolve a thread would require that you can edit your first post, which I think you should be allowed to do after 118 posts.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|