namespace WindowsFormsApplication1 { public partial class Form4 : Form { public Form4() { InitializeComponent(); } public class LigneIp { public string colonne1 { get; set; } public string colonne2 { get; set; } } private void Form4_Load(object sender, EventArgs e) { //Au click appelle le formulaire Form1 pour pouvoir prendre les variables désirées Form1 nbsubnet = (Form1)this.Owner; string nbsubnetr = nbsubnet.nbsubnetr(); Form1 ip = (Form1)this.Owner; string ipr = ip.ipr(); Form1 ipb = (Form1)this.Owner; string ipi = ipb.ipi(); //Convertir la valeur retourné en dec pour le tableau int subnetn = Convert.ToInt32(nbsubnetr); int x = Convert.ToInt32(ipi); double nbexpo = Math.Pow(2, (Math.Ceiling(Math.Log10(subnetn) / Math.Log10(2)))); textBox1.Text = nbexpo.ToString(); List<LigneIp> l = new List<LigneIp>(); for (int i = 0; i <= (nbexpo - 1); i++) { if (nbexpo * i <= 256) l.Add(new LigneIp() { colonne1 = "Adresse " + i, colonne2 = ipr + x + "." + nbexpo * i, } ); for (int y = 0;(nbexpo * i) >= 256 & y <= (nbexpo - 1); y++, x++) { if (nbexpo * y <= 256) l.Add(new LigneIp() { colonne1 = "Adresse " + y , colonne2 = ipr + x + "." + nbexpo * y } ); } } dataGridView1.DataSource = l; } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionint subnetn = Convert.ToInt32(nbsubnetr); int x = Convert.ToInt32(ipi); double nbexpo = Math.Pow(2, (Math.Ceiling(Math.Log10(subnetn) / Math.Log10(2)))); textBox1.Text = nbexpo.ToString(); List<LigneIp> l = new List<LigneIp>(); for (int i = 0; i <= (nbexpo - 1); i++) { if (nbexpo * i <= 256) { l.Add(new LigneIp() { colonne1 = "Adresse " + i, colonne2 = ipr + x + "." + nbexpo * i, } ); } else { x++; for (int y = 0; (nbexpo * i) >= 256 & y <= (nbexpo - 16); y++) { if (nbexpo * y <= 256) l.Add(new LigneIp() { colonne1 = "Adresse " + y, colonne2 = ipr + x + "." + nbexpo * y } ); } } } dataGridView1.DataSource = l; } } }