2017-06-08 3 views
0

J'ai un problème parce que j'écris un programme en C# sur l'algorithme fcfs et j'ai une question comment importer d'un datagridview dans un algorithme et puis montrer sur mon datagridview2 voici mon code:Premier arrivé premier jeu

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace Projekt 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 

     } 
     DataTable table = new DataTable(); 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      table.Columns.Add("Process", typeof(int)); 
      table.Columns.Add("Arrival Time", typeof(string)); 
      table.Columns.Add("Burst Time", typeof(string)); 
      table.Columns.Add("Piority", typeof(int)); 

      table.Rows.Add("1"); 
      table.Rows.Add("2"); 
      table.Rows.Add("3"); 
      table.Rows.Add("4"); 


      dataGridView1.DataSource = table; 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 

      Random rand = new Random(); 
      dataGridView1[1, 0].Value = rand.Next(5, 30); 
      dataGridView1[2, 0].Value = rand.Next(5, 30); 
      dataGridView1[3, 0].Value = rand.Next(5, 30); 
      dataGridView1[1, 1].Value = rand.Next(5, 30); 
      dataGridView1[2, 1].Value = rand.Next(5, 30); 
      dataGridView1[3, 1].Value = rand.Next(5, 30); 
      dataGridView1[1, 2].Value = rand.Next(5, 30); 
      dataGridView1[2, 2].Value = rand.Next(5, 30); 
      dataGridView1[3, 2].Value = rand.Next(5, 30); 
      dataGridView1[1, 3].Value = rand.Next(5, 30); 
      dataGridView1[2, 3].Value = rand.Next(5, 30); 
      dataGridView1[3, 3].Value = rand.Next(5, 30); 
     } 

     private void FCFS_Click(object sender, EventArgs e) 
     { 

     } 
    } 
} 

pourriez-vous me aider à ce problème que je

+0

Vous pouvez créer une classe qui représente le processus. Et puis utilisez une collection pour lier la source de données de la grille. –

+1

Pourquoi est-ce que 'algorithm' est étiqueté lol. – jdmdevdotnet

Répondre

0

code Essayez ci-dessous. Les colonnes 0 & 3 sont int, tandis que les colonnes 1 & sont des chaînes de 2. Vous ne pouvez pas mettre un int dans une colonne de chaîne

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace Projekt 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 

     } 
     DataTable table = new DataTable(); 
     DataTable table2 = new DataTable(); 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      table.Columns.Add("Process", typeof(int)); 
      table.Columns.Add("Arrival Time", typeof(string)); 
      table.Columns.Add("Burst Time", typeof(string)); 
      table.Columns.Add("Piority", typeof(int)); 

      table.Rows.Add("1"); 
      table.Rows.Add("2"); 
      table.Rows.Add("3"); 
      table.Rows.Add("4"); 


      dataGridView1.DataSource = table; 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 

      Random rand = new Random(); 
      table.Rows[0][0] = rand.Next(5, 30); 
      table.Rows[1][0] = rand.Next(5, 30); 
      table.Rows[2][0] = rand.Next(5, 30); 
      table.Rows[3][0] = rand.Next(5, 30); 
      table.Rows[0][3] = rand.Next(5, 30); 
      table.Rows[1][3] = rand.Next(5, 30); 
      table.Rows[2][3] = rand.Next(5, 30); 
      table.Rows[3][3] = rand.Next(5, 30); 

      dataGridView1 = null; //to force update 
      dataGridView1.DataSource = table; 
     } 

     private void FCFS_Click(object sender, EventArgs e) 
     { 
      table2 = table.Clone(); 
      dataGridView2.DataSource = table2; 

     } 
    } 
} 
0

Ces deux lignes ne fonctionne pas

dataGridView1 = null; // pour forcer la mise à jour dataGridView1.DataSource = table;

Ils clone seulement des colonnes non lignes avec des valeurs