Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
//Recupero dati cliente
        DataTable GetCliItems()
        {
            try
            {
                con.ConnectionString = "server=localhost;User Id=root;password=*****;database=******";
                //con.Open();

                //query per la visualizzazione di tutti i clienti
                string query = "select nome, cognome, indirizzo, telefono, cellulare, referente, note from clienti where rif_agente ='" + comboBox1.Text + "'";
                //adapter per eseguire la query
                adapter = new MySqlDataAdapter(query, con);
                DataSet DS = new DataSet();

                //restituisce il risultato della query nel dataset
                adapter.Fill(DS);


                return DS.Tables[0];


            }
            catch (Exception ex)
            {
                MessageBox.Show("Errore durante il recupero delle informazioni.\n\n" + ex.Message, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally { con.Close(); }

            return null;
        }//this is the table
//Costruzione della tabella con i valori riga tramite array di celle
                        PdfPTable tabellaCliente = new PdfPTable(7);
                        tabellaCliente.WidthPercentage = 100;//Retrieve data from dataTable
for (int i = 0; i < DTCliAg.Rows.Count; i++)
                        {
                            string nome = DTCliAg.Rows[i]["nome"].ToString();
                            string cognome = DTCliAg.Rows[i]["cognome"].ToString();
                            string indirizzo = DTCliAg.Rows[i]["indirizzo"].ToString();
                            string telefono = DTCliAg.Rows[i]["telefono"].ToString();
                            string cellulare = DTCliAg.Rows[i]["cellulare"].ToString();
                            string referente = DTCliAg.Rows[i]["referente"].ToString();
                            string note = DTCliAg.Rows[i]["note"].ToString();

                            PdfPCell[] cellsCli = new PdfPCell[] {  new PdfPCell(new Phrase(nome,fontStampaTable)),
                                                                    new PdfPCell(new Phrase(cognome,fontStampaTable)),
                                                                    new PdfPCell(new Phrase(indirizzo,fontStampaTable)),
                                                                    new PdfPCell(new Phrase(telefono,fontStampaTable)),
                                                                    new PdfPCell(new Phrase(cellulare,fontStampaTable)),
                                                                    new PdfPCell(new Phrase(referente,fontStampaTable)),
                                                                    new PdfPCell(new Phrase(note,fontStampaTable))};

                            for (int j = 0; j < 7; j++)
                            {
                                cellsCli[j].HorizontalAlignment = 0;
                                cellsCli[j].PaddingBottom = 3f;
                                cellsCli[j].Border = 0;
                            }

                            PdfPRow rowCli = new PdfPRow(cellsCli);
                            tabellaCliente.Rows.Add(rowCli);
Posted

Created the PdfPCell[] outside the loop.. after the statement
C#
PdfPTable tabellaCliente = new PdfPTable(7);

and inside the loop
C#
cellsCli[i]=new PdfPCell[]{....
 
Share this answer
 
i solved with
PdfPTable tabellaCliente = new PdfPTable(7);
tabellaCliente.WidthPercentage = 100;

inside the for loop...simply.
thank you anyway!!
 
Share this answer
 

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