I am developing an application that accesses a SQL database, then displays the customer, order, and store information on various tabs. I wrote am implementing a function that opens a new form displaying the individual invoice. This new form "imports", so to speak the data from the current form by means of the following code:
private void Cmds_BoutonFacture_Click(object sender, EventArgs e)
{
//Initialisation variables d'exportation
//A AJOUTER: UNE EVENEMENT QUI EFFACE LES DONNEES PUBLIQUES QUAND
//LA FENETRE FACTURE EST FERME, POUR UTILISER DANS LA FONCTION
//BATCH_PRINT (A AJOUTER)
Exp_NumCmd = this.Cmds_Num.Text;
Exp_NumMag = this.Cmds_NumMag.Text;
Exp_NumClt = this.Cmds_NumClt.Text;
Exp_NomClt = this.Cmds_NomClt.Text;
Exp_PrenomClt = this.Cmds_PrenomClt.Text;
Exp_NumAdr = this.Cmds_NumAdr.Text;
Exp_Adr = this.Cmds_Adr.Text;
Exp_CompAdr = this.Cmds_CompAdr.Text;
Exp_CP = this.Cmds_CP.Text;
Exp_Ville = this.Cmds_Ville.Text;
Exp_Tel = this.Cmds_Tel.Text;
Exp_DateLiv = this.Cmds_dateLiv.Text;
//Vous avez changer la variable de status livraison!!
Facture CmdOut = new Facture();
//CmdOut.Sample = sample;
//CETTE PARTIE FAIT APPEL A UNE FONCTION QUI EXISTE DANS FACTURE.CS
CmdOut.SetDisplayValues(Exp_NumCmd, Exp_NumMag, Exp_NumClt, Exp_NomClt, Exp_PrenomClt, Exp_NumAdr, Exp_Adr, Exp_CompAdr, Exp_CP, Exp_Ville, Exp_Tel, Exp_DateLiv);
CmdOut.ShowDialog();
}
Don't worry about the comments, this part works, I included because it shows what I want to do with the next part of the form.
Ok, so as you may see in the previous code, all I am doing is sending the information contained in a label to another label (these are the equivalents in the second form):
public void SetDisplayValues(string NumCmd, string NumMag, string NumClt, string NomClt, string PrenomClt, string NumAdr, string Adr, string CompAdr, string CP, string Ville, string Tel, string DateLiv)
{
this.Facture_NumCmd.Text = NumCmd;
this.Facture_NumMag.Text = NumMag;
this.Facture_NumClt.Text = NumClt;
this.Facture_NomClt.Text = NomClt;
this.Facture_PrenomClt.Text = PrenomClt;
this.Facture_NumAdr.Text = NumAdr;
this.Facture_Adr.Text = Adr;
this.Facture_CP.Text = CP;
this.Facture_Ville.Text = Ville;
this.Facture_Tel.Text = Tel;
this.Facture_dateLiv.Text = DateLiv;
}
But the second part of the windows form contains a listview element, which I have never had to "import" before.
Now in order to have the listview contents available for implementing it into a print function (I am using a dll which will fill the interactive forms of a pdf document with the information that the second form will contain - again this works so far for the label elements, I haven't tested it for the listview as I haven't gotten any information to go into the second form yet), I decided to have the data the listview contains be stored into a DataTable, using the following code:
internal DataTable GetTable()
{
DataTable dtable = new DataTable();
string n_reference;
string n_type;
string n_designation;
string n_quantite;
dtable.Columns.Add("Reference", typeof(string));
dtable.Columns.Add("Type", typeof(string));
dtable.Columns.Add("Designation", typeof(string));
dtable.Columns.Add("Quantité", typeof(string));
for (int i = 0; i < CmdAffiche.meubles.Count; i++)
{
n_reference = CmdAffiche.meubles[i].reference.ToString();
n_type = CmdAffiche.meubles[i].type;
n_designation = CmdAffiche.meubles[i].designation;
n_quantite = CmdAffiche.meubles[i].quantite.ToString();
dtable.Rows.Add(n_reference, n_type, n_designation, n_quantite);
}
return dtable;
}
I have no idea, however, as of how to access this datatable from my second form. I have tried making the Datatable public, it has no effect, I know I have to make it so I can use:
foreach(DataRow in dtable.Rows){
listViewUsers.Items.Add(new ListViewItem(new string[]{row[name of row"]})); }
which would be added in the second form (I think), adding a new row element for each row i need to add, and the .tostring if the item is not in string (I am not sure if what I just wrote above is correct, I haven't tested it).
I am out of ideas, I know I have access it, but I don't know why, and I haven't found anything resembling my issue on the net (I have spent several hours searching). I am open to suggestions, please. Any help is appreciated.