How to go through datagrid to form an email with the data of it and remove some columns? vb.net

0

I'm going through a datagrid in vb.net and with the information that has an email in html format to send it by mail, everything works fine, only that the datagrid has two columns that are marked in the photo that are with the property invisible and which when I go through the datagrid also appear in the mail, another is also the last column I do not want to leave in the mail, as would be done to exclude those columns and the last one when going through the datagrid?

photo:

Code with which I go through the datagrid and form a table in html format which is sent by mail.

 Dim BodyCorre As String
    BodyCorre = "<table width='80%' style='border:Solid 2px Black;' 
    bgcolor='#3366FF' ><tr><th>ACTIVIDAD</th><th>RESPONSABLE</th> 
   <th>ESTATUS</th><th></th><th></th><th>FCH. TERMINO</th><th></th></tr>"
    For Each Row As DataGridViewRow In DataGridView1.Rows
    BodyCorre += "<tr bgcolor=#c3cbcb>"
    For Each cell As DataGridViewCell In Row.Cells
    BodyCorre += "<td >" & cell.Value & "</td>
    Next
    Next
    BodyCorre += "</table>"

the mail that arrives is the following:

    
asked by Manny 20.09.2018 в 17:46
source

1 answer

1

What you can do is validate the indexes of the cells that you do not want to be added, something like this:

   Dim BodyCorre As String
    BodyCorre = "<table width='80%' style='border:Solid 2px Black;' bgcolor='#3366FF'><tr><th>ACTIVIDAD</th><th>RESPONSABLE</th><th>ESTATUS</th><th></th><th></th><th>FCH. TERMINO</th><th></th></tr>"
    For Each Row As DataGridViewRow In Me.DataGridView1.Rows
        BodyCorre = String.Format("{0}<tr bgcolor=#c3cbcb>", BodyCorre)
        For Each cell As DataGridViewCell In Row.Cells


            If Convert.ToString(Row.Cells(1).Value) <> Convert.ToString(cell.Value) And Convert.ToString(Row.Cells(2).Value) <> Convert.ToString(cell.Value) And Convert.ToString(Row.Cells(6).Value) <> Convert.ToString(cell.Value) Then
                BodyCorre = String.Format("{0}<td>{1}</td>", BodyCorre, cell.Value)
            End If


        Next
    Next

    BodyCorre = String.Format("{0} </table>", BodyCorre)

In the if you indicate that while the value of the cell you are traveling in the foreach is different from the value of the cell with the specific index that you do not want to take into account, concatenate it to your variable to build the table

    
answered by 20.09.2018 / 18:52
source