我应该如何使用DataGridViewCellFormattingEventArgs发送即时消息的DataGrid结果

时间:2018-09-05 03:06:54

标签: vb.net

下面是DataGridViewCellFormattingEventArgs的代码

Public Sub DataGridView_CellFormatting(ByVal sender As Object, 
    ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) 
    Handles DataGrid.CellFormatting

    For i As Integer = 0 To dt_result.Rows.Count() - 1

        If dt_result.Rows.Count() - 0 Then
            DataGrid.Rows(i).DefaultCellStyle.BackColor = Color.Green
        End If

    Next
    Dim drv As DataRowView
    If e.RowIndex >= 0 Then
        If e.RowIndex <= dt_result.Rows.Count - 1 Then
            drv = dt_result.DefaultView.Item(e.RowIndex)
            Dim c As Color
            If drv.Item("Status").ToString = "Working" Then
                c = Color.Green
            Else
                c = Color.Red
            End If
            e.CellStyle.BackColor = c
        End If
    End If
    DataGrid.DataSource = dt_result

End Sub

以下是我使用SMTP发送邮件的功能

Try
    'Create instance of MailMessage Class
    Dim msg As New MailMessage()
    'Assign From mail address
    msg.From = New MailAddress("Emailaddress")
    'Set To mail address
    msg.[To].Add(New MailAddress("Emailadress"))
    'Set Subject of mail
    msg.Subject = "Subject of Mail"
    'Create Mail Body
    msg.Body = "Body of Mail"
    msg.Body += "DataGrid Result from DataGridViewCellFormattingEventArgs" <-- Here's my Target that DataGridResult will be here

    'for sending body as HTML
    msg.IsBodyHtml = True
    'Create Instance of SMTP Class
    Dim SmtpServer As New SmtpClient("smtp.gmail.com")
    'Assign Host
    'SmtpServer.Host = ""
    'Assign Post Number
    SmtpServer.Port = 587
    'Setting the credential for the sender
    SmtpServer.Credentials = New System.Net.NetworkCredential("Email address", "Password")
    'Enable teh Secure Soket Layer to Encrypte the connection 
    SmtpServer.EnableSsl = True
    'Sending the message
    SmtpServer.Send(msg)
    LblMessage.Text = "Mail Sent Sucessfully "
           Catch ex As Exception
    LblMessage.Text = "Issue while sending the mail Please check."
End Try

0 个答案:

没有答案