2015-10-03 80 views
1

我想添加Mark1,Mark2,Mark3,Mark4,Mark5並將其分配到Sum以顯示在gridview中。收藏列表和網格視圖

我想通過任何函數添加這些標記並將其分配給Sum屬性。怎麼做?感謝

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void procees() 
    {    
     List<student> ml= new List<student>(); 

     student s1 = new student() { 
      Name = "ram", 
      Id = "gn01", 
      Mark1 = 90, 
      Mark2 = 89, 
      Mark3 = 75, 
      Mark4 = 45, 
      Mark5 = 65, 
      Sum = "" 
     }; 
     ml.Add(s1); 

     dataGridView1.DataSource = ml; 
    } 


    private void button1_Click(object sender, EventArgs e) 
    { 
     procees(); 
    } 
} 

public class student 
{ 
    private string name; 

    public string Name 
    { 
     get { return name; } 
     set { name = value; } 
    } 

    private string id; 

    public string Id 
    { 
     get { return id; } 
     set { id = value; } 
    } 

    private int mark1; 

    public int Mark1 
    { 
     get { return mark1; } 
     set { mark1 = value; } 
    } 
    private int mark2; 

    public int Mark2 
    { 
     get { return mark2; } 
     set { mark2 = value; } 
    } 
    private int mark3; 

    public int Mark3 
    { 
     get { return mark3; } 
     set { mark3 = value; } 
    } 
    private int mark4; 

    public int Mark4 
    { 
     get { return mark4; } 
     set { mark4 = value; } 
    } 
    private int mark5; 

    public int Mark5 
    { 
     get { return mark5; } 
     set { mark5 = value; } 
    } 
    private int sum; 

    public int Sum 
    { 
     get { return sum; } 
     set { sum = value; } 
    } 
} 
+0

你想加入的GridView,然後標記使它的總數顯示在最後一列? –

+0

是的,我想加總,並顯示在最後一列.. vijay kumbhoje –

回答

1

刪除私人領域「和」:

private int sum; 

讓公共的財產「點心」來計算的總和:

public int Sum 
{ 
    get { return Mark1 + Mark2 + Mark3 + Mark4 + Mark5; } 
} 
+0

Thanks..sorry非常晚的答覆.. –