View Full Version : [VB2010] Email addresses from datagridview to textbox

09-08-2011, 10:38 AM
I want to know how I can select multiple emailaddresses (rows) in a datagridview and enter them separated by a semicolon in a textbox or select select a single row press the add button to add the emailaddress to the textbox, then select another row and after pressing the add button again that emailaddress is entered into the textbox, behind the first add emailaddress separated by a semicolon.

Just like with outlook.

Can anyone help me with this?

09-10-2011, 12:00 PM
Doesn't anyone has an answer for the problem?

09-10-2011, 09:29 PM
You should probably mention the language you would like help in.

09-10-2011, 10:46 PM
You should probably mention the language you would like help in.

My bad, I use VB2010

10-13-2011, 09:10 PM
Is there no one who can help me with this?

There must be someone?

10-14-2011, 06:47 PM
.net mail to (http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx)

then somewhere before this line

Dim [to] As New MailAddress("ben@contoso.com")

populate a string array with emails and then do

......MailAddress(strEmails[0] + ";" + strEmails[1]..... and so on (side note... i think VB uses & instead of +)

then you could similarly populate the textbox with it or am i missing something (*hope this answers Q)
textbox1.Text= "whatever you want"

10-15-2011, 02:17 PM
Thanks for your reply.

What I try is something similar to the microsoft office outlook 2007, when creating a new email, and then To.. to select the addresses. This is the part I'm looking for (see attachment), when selecting an address in the list and press the TO..., CC.. or BCC button to add the email address to the textbox.

How to do that?

10-17-2011, 11:40 AM
cycle through the data to get the selected fields, something like this:

For i = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(i).Cells("EMail").Selected Then
'do stuff to DataGridView1.Rows(i).
End If

10-28-2011, 08:53 PM
Sorry for replying after a long period.

I've been trying get it working and came up with the following code:

Private Sub ToButton_Click(sender As System.Object, e As System.EventArgs) Handles ToButton.Click
Dim tmpstr As String = ""
Dim cnt As Integer = 0
Dim virgin As Boolean = True
For cnt = 0 To (DataGridViewX1.Rows.Count - 1)
If Not DataGridViewX1.Rows(cnt).Cells(3).Value.ToString() Is Nothing Then
If Not DataGridViewX1.Rows(cnt).Cells(3).Value.ToString().Length = 0 Then
If Not virgin Then
tmpstr += "; "
End If
tmpstr += DataGridViewX1.Rows(cnt).Cells(3).Value.ToString()
virgin = False
End If
End If
ToTextBox.Text = tmpstr
End Sub

The problem with this code is that it even if I only select one row, it enters all the rows (email addresses, separated by semicolon) into the textbox.

What I want is to be able to select a single row and add that email address to the textbox, and when I select another row I want to add that email address to the textbox, behind the first entered email address (just as outlook).


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum