private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { comboBox2.Items.Clear(); StrategiAlgoritma S = new StrategiAlgoritma(openFileDialog1.FileName); List <string> ListCombo = S.GetGraf(); foreach (string text in ListCombo) { if (text == comboBox1.SelectedItem.ToString()) { continue; } //comboBox1.Items.Add(text); comboBox2.Items.Add(text); } }
private void button1_Click(object sender, EventArgs e) { //create a viewer object Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer(); //create a graph object Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph"); openFileDialog1.Filter = "*.txt|*.txt|All files (*.*)|*.*"; openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory(); openFileDialog1.Title = "Masukkan file input"; // Show file dialog DialogResult dr = openFileDialog1.ShowDialog(); if (dr == DialogResult.OK) { button1.Text = openFileDialog1.SafeFileName; namafile = openFileDialog1.FileName; StrategiAlgoritma S = new StrategiAlgoritma(openFileDialog1.FileName); List <string> semua = new List <string>(); using (StreamReader sr = new StreamReader(openFileDialog1.OpenFile())) { string line = sr.ReadLine(); if (line == null || line == "0") { MessageBox.Show("File is empty", "Warning!!!"); } else { comboBox1.Items.Clear(); comboBox2.Items.Clear(); while (sr.Peek() >= 0) { line = sr.ReadLine(); // Read file line by line string[] cur_line = line.Split(' '); graph.AddEdge(cur_line[0], cur_line[1]).Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None; int i = 0; bool sama = false; while (i < semua.Count && sama == false) { if (semua.Contains(cur_line[0])) { sama = true; } i++; } if (sama == false) { semua.Add(cur_line[0]); } } List <string> ListCombo = S.GetGraf(); foreach (string text in ListCombo) { comboBox1.Items.Add(text); comboBox2.Items.Add(text); } } } viewer.Graph = graph; panel1.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; panel1.Controls.Add(viewer); panel1.ResumeLayout(); // Masukkan Daftar Akun A this.Controls.Add(comboBox1); // Masukkan Daftar Akun B this.Controls.Add(comboBox2); } }