Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have solution and work fine
 
I need in ,,if (c == 2),,  to add multiple columns with date and time...some help?


What I have tried:

//Adding DataRow  
            foreach (DataGridViewRow row in mp_racun_listaDataGridView.Rows)  
            {  
                int c = 0;  
                foreach (DataGridViewCell cell in row.Cells)  
                {  
                    if (c == 2)  
                    {  
                        PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString().Split(' ')[0], calibri));  
                        pdfTable.AddCell(cell2);  
                    }  
                    else  
                    {  
                        PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString(), calibri));  
                        pdfTable.AddCell(cell2);  
                    }  
                    c++;  
                }  
            }  
Posted
Updated 21-Sep-18 8:52am
Comments
Richard Deeming 20-Sep-18 8:21am    
"I have solution and work fine"

So why post this question if you already have a working solution?!
Alek Massey 20-Sep-18 10:19am    
Possibly he means it works fine as is but he doesn't know how to add multiple datetime columns.
Goran Bibic 20-Sep-18 11:21am    
Of course...one column work...multiple dont work...some help...not critics before read the question...Thanks Alek Massey
Goran Bibic 21-Sep-18 2:10am    
Yes
Alek Massey 20-Sep-18 10:40am    
Are you attempting to separate the date and time out of a cell with datetime?

1 solution

Assuming you want to split the cell value on the space character, and add each part as a new cell:
if (c == 2)  
{  
    string[] parts = cell.Value.ToString().Split(' ');
    foreach (string value in parts)
    {
        PdfPCell cell2 = new PdfPCell(new Phrase(value, calibri));  
        pdfTable.AddCell(cell2);  
    }
}

If that's not what you're trying to do, or if it doesn't work, then you'll need to provide more details.
 
Share this answer
 
Comments
Goran Bibic 22-Sep-18 1:57am    
This work, but that is for one column people...I NEED FOR MULTIPLE COLUMN SIX TIMES WRITE.THANK YOU
Richard Deeming 24-Sep-18 13:32pm    
WE CANNOT READ YOUR MIND.

When you don't explain your problem clearly, we end up having to guess what you're asking for.

If we guess incorrectly, then you need to explain the problem more clearly.

Simply repeating the same words, like an English tourist trying to make a non-English-speaking local magically understand English, doesn't help.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900