Results 1 to 9 of 9

Thread: [RESOLVED] [2005]trying to create a custom string

  1. #1

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Resolved [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......
    C# and WPF developer
    My Website:
    http://singlebits.com/

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005]trying to create a custom string

    vb.net Code:
    1. Public Class WebPageInfo
    2.  
    3.     Private _title As String
    4.     Private _url As String
    5.  
    6.     Public Property Title() As String
    7.         Get
    8.             Return Me._title
    9.         End Get
    10.         Set(ByVal value As String)
    11.             Me._title = value
    12.         End Set
    13.     End Property
    14.  
    15.     Public Property Url() As String
    16.         Get
    17.             Return Me._url
    18.         End Get
    19.         Set(ByVal value As String)
    20.             Me._url = value
    21.         End Set
    22.     End Property
    23.  
    24.     Public Sub New(ByVal title As String, ByVal url As String)
    25.         Me._title = title
    26.         Me._url = url
    27.     End Sub
    28.  
    29. End Class
    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private pageInfos As New System.ComponentModel.BindingList(Of WebPageInfo)
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         Me.BindingSource1.DataSource = Me.pageInfos
    7.         Me.ListBox1.DisplayMember = "Title"
    8.         Me.ListBox1.ValueMember = "Url"
    9.         Me.ListBox1.DataSource = Me.BindingSource1
    10.     End Sub
    11.  
    12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    13.         Me.pageInfos.Add(New WebPageInfo(Me.WebBrowser1.DocumentTitle, _
    14.                                          Me.WebBrowser1.Url.ToString()))
    15.     End Sub
    16.  
    17. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [2005]trying to create a custom string

    Thank you very much....
    C# and WPF developer
    My Website:
    http://singlebits.com/

  4. #4

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    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
    C# and WPF developer
    My Website:
    http://singlebits.com/

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [RESOLVED] [2005]trying to create a custom string

    So, what method could i use ?
    C# and WPF developer
    My Website:
    http://singlebits.com/

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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"
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    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...
    C# and WPF developer
    My Website:
    http://singlebits.com/

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width