Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VB.NET ListBox strings , +
I am Creating a Client that uses email to send and recieve text messages. I only have to problems when i recieve the mail from the server it goes into my listbox but how do i make that listbox string, when selected, open the body of the message in a richtextbox. Here is my code so far.

Also here is a picture of the GUI so you can see the problem a little more clearly.
Click Here For GUI Picture

The messages are put into the Inbox i just cant display the body of the message in the richtext box when selected from the listbox. Any Help will be greatly appreciated! Thanks!
 
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'variable declaration
        Dim strMailServer, strUsername, strPassword, strFrom, strSubject, strToo, strBody, strMailContent As String
        Dim popConn As Text_Me_Now.POP3
        Dim mailMess As Text_Me_Now.EmailMessage
        Dim intMessCnt, i As Integer
 
        'set the variables to the input boxes
        strMailServer = "pop.gmx.com"
        strUsername = "xxxxxxx@gmx.com"
        strPassword = "xxxxxxx"
 
 
 
        'Disable the button when proccessing
        Button2.Enabled = False
 
        'create the objects
        popConn = New Text_Me_Now.POP3
        mailMess = New Text_Me_Now.EmailMessage
 
        'if we have got to this point, try and connect to the server
        popConn.POPConnect(strMailServer, strUsername, strPassword)
 
        'now we have a connection, see if there are any mails on the server
        intMessCnt = popConn.GetMailStat()
 
        'now, see if we have returned any messages
        If intMessCnt > 0 Then
 
            'clear contents of the list and add the heading
            ListBox1.Items.Clear()
 
            'if we returned some messages, loop through each one and get the details
            For i = 1 To intMessCnt
 
                'load the entire content of the mail into a string
                strMailContent = popConn.GetMailMessage(i)
 
                'call the functions to get the various parts out of the email
                strFrom = mailMess.ParseEmail(strMailContent, "From:")
                strSubject = mailMess.ParseEmail(strMailContent, "Subject:")
                strToo = mailMess.ParseEmail(strMailContent, "To:")
                strBody = mailMess.ParseBody()
 
                'add email details to the list box
                ListBox1.Items.Add(strFrom & ", " & strSubject)
 
                'un-comment to display full details of the email in a message box
                'MsgBox("From: " & strFrom & vbNewLine & "Too: " & strToo & vbNewLine & "Subject: " & strSubject & _
                'vbNewLine & "Body: " & strBody)

                'call close method to delete the emails.
            Next i
        End If
        'Quit the connection to the server
        popConn.CloseConn()
 
        Button2.Enabled = True
 
    End Sub
 
    Private Sub ListBox1_SelectedIndexChanged(sender As Object, 
    End Sub
Posted 22-Feb-13 18:24pm
Edited 22-Feb-13 19:39pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

code for you...
 
Sorry ... not enaugh space..
 
download code here
http://www.megafileupload.com/en/file/395411/CustomListItem-rar.html[^]
  Permalink  
v2
Comments
Gray_Ang3l at 23-Feb-13 2:07am
   
Wow, didn't realize that it would be that much code. Thank you for all the effort!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

e9net, had a solution but i figured out the easiest way to do it by simply adding the following lines...
 
    
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        RichTextBox1.Clear()
        RichTextBox1.Text = ListBox1.SelectedItem
    End Sub
 
It was a lot less code and works. Thanks for your help though!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100