Results 1 to 7 of 7

Thread: how to pass values to an event and invoke them from another class ?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    27

    how to pass values to an event and invoke them from another class ?

    what i am trying to do is i am scrapping data from a website it contains an image as well as text contexts i have used simple regex to get the contents out .
    now what i am trying to save those image currently i am downloading the image and saving it .
    now the problem is as i save them i add the text-items to the listview from one class ,

    i know how to add those images to the imagelist , my problem is setting those each images in listview from another class , when ever i add items to listview i need to draw an image inside the listview , which is done

    save image code:
    PHP Code:
      Public Function saveimage(ByVal url As StringByVal name As String) As String
                Dim request 
    As HttpWebRequest TryCast(WebRequest.Create(url), HttpWebRequest)

                
    Dim response As HttpWebResponse TryCast(request.GetResponse(), HttpWebResponse)
                
    Dim stream As Stream response.GetResponseStream()
                
    Dim ms As New MemoryStream()
                
    Dim bw As New BinaryWriter(ms)
                
    Dim br As New BinaryReader(stream)
                
    bw.Write(br.ReadBytes(CInt(response.ContentLength)))
                
    ms.Position 0
                Dim fred 
    As Bitmap TryCast(Bitmap.FromStream(ms), Bitmap)
               

                
    Dim imagePath As String "C:\img\" + name + ".jpeg"


                fred.Save(imagePath)

                Return name
            End Function 
    PHP Code:
    Private Sub ListView1_DrawSubItem(sender As ObjectAs DrawListViewSubItemEventArgsHandles ListView1.DrawSubItem
            
    If e.SubItem.Text imagestring Then
                e
    .Graphics.DrawImage(ImageList1.Images(nindex), e.Bounds.Xe.Bounds.Ye.Bounds.Heighte.Bounds.Height)
            
    End If
        
    End Sub 
    i want to invoke this event when ever an item is added , i dont know how to achive that .

    is there any way to pass imagestring values and imagelist index from the function class to the form or is there any way i cant recreate a similar event in my function class and update my listview.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: how to pass values to an event and invoke them from another class ?

    I am not sure I follow. DrawSubItem firing depends on the listview OwnerDraw property being set to true. Did you do that? The DrawSubItem event doesn't need to be invoked, it will fire automatically whenever the listview needs to draw a given subitem, so long as OwnerDraw is true.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    27

    Re: how to pass values to an event and invoke them from another class ?

    Quote Originally Posted by kleinma View Post
    I am not sure I follow. DrawSubItem firing depends on the listview OwnerDraw property being set to true. Did you do that? The DrawSubItem event doesn't need to be invoked, it will fire automatically whenever the listview needs to draw a given subitem, so long as OwnerDraw is true.
    yeah i know that ,and yes i have set the property and its working .
    Attachment 127833
    Code:
      Private Sub ListView1_DrawColumnHeader(sender As Object, e As DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader
            e.DrawDefault = True
        End Sub
    what i want to do is the listview drawsubitem event works only when the the image name(imagestring) and imagelist index no(ImageList1.Images(nindex)) is provided
    Code:
     If e.SubItem.Text = imagestring Then 
                e.Graphics.DrawImage(ImageList1.Images(nindex), e.Bounds.X, e.Bounds.Y, e.Bounds.Height, e.Bounds.Height) 
            End If
    is there some way to pass these values into the event form another class. basically m problem is that i have wriiten all the codes in a class , i just call them in my main form . i am using httpwebrequest and multithreading .to get the site source retrive data and pass that to the listview
    Last edited by Priv4teByte.exe; Jun 24th, 2015 at 10:13 AM.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: how to pass values to an event and invoke them from another class ?

    You can't pass them in from another class as part of the arguments, but if that other class is in scope for the method then the method can go get the information it needs from the other class when it wants to.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    27

    Re: how to pass values to an event and invoke them from another class ?

    okay , but can i create custom event in my class to do the same ?

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: how to pass values to an event and invoke them from another class ?

    where do you save any thing to an imagelist? what is return name? are you trying to get a countrys flag in the lstview?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2014
    Posts
    27

    Re: how to pass values to an event and invoke them from another class ?

    am an idiot , i have done what i wanted i was using listview till now , i forgot that we had Datagridview in Visualstudio . i have a couple of links and images that i needed to display which is done now using the help of datagridview .
    there is a tiny bit problem i am not most familiar with datagridview control i need to increase the height of all rows so that the image is a prefect fix .can someone tell me how can i do that ?

    Name:  pp.png
Views: 92
Size:  28.3 KB

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