sadeq tlb

sadeq tlb

  • NA
  • 6
  • 751

how to bind grid view in C#

Aug 15 2016 1:36 AM
i have gridview and i want bind it from data base but it not bind some Cells. it's class of table:
  1. [Key]  
  2. [Required]  
  3. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  4. [Column("FldKeyId")]  
  5. public int MyKeyId { getset; }  
  6. [Required]  
  7. public Machine Machine { getset; }    
  8. [Required]  
  9. public Employee Employee { getset; }  
  10. [Required]  
  11. public Shift Shift { getset; }  
  12. [Required]  
  13. [Column ("FldStartTime")]  
  14. public DateTime MyStartTime { getset; }  
  15. [Required]  
  16. [Column ("FldEndTime")]  
  17. public DateTime MyEndTime { getset; }  
  18. [Column("FldModificationDate")]  
  19. [Required]  
  20. public DateTime ModificationDate { getset; }    [Key]  
  21. [Required]  
  22. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
  23. [Column("FldKeyId")]  
  24. public int MyKeyId { getset; }  
  25. [Required]  
  26. public Machine Machine { getset; }    
  27. [Required]  
  28. public Employee Employee { getset; }  
  29. [Required]  
  30. public Shift Shift { getset; }  
  31. [Required]  
  32. [Column ("FldStartTime")]  
  33. public DateTime MyStartTime { getset; }  
  34. [Required]  
  35. [Column ("FldEndTime")]  
  36. public DateTime MyEndTime { getset; }  
  37. [Column("FldModificationDate")]  
  38. [Required]  
  39. public DateTime ModificationDate { getset; }  

that's my code for bind

  1. void RefreshBreakGrid()  
  2.     {  
  3.         dgvcolDate.DataPropertyName = "ModificationDate";  
  4.         dgvcolstarttime.DataPropertyName = "MyStartTime";  
  5.         dgvcolendtime.DataPropertyName = "MyEndTime";  
  6.   
  7.         dgvcolemployee.DataSource = Employee.GetAllEmployee();  
  8.         dgvcolemployee.DisplayMember = "MyName";  
  9.         dgvcolemployee.ValueMember = "MyKeyId";  
  10.         dgvcolemployee.DataPropertyName = "Employee";  
  11.   
  12.   
  13.         dgvcolmachine.DataSource = Machine.GetAllMachine();  
  14.         dgvcolmachine.DisplayMember = "MyName";  
  15.         dgvcolmachine.ValueMember = "MyKeyId";  
  16.         dgvcolmachine.DataPropertyName = "MyName";  
  17.   
  18.         dgvcolshift.DataSource = Shift.GetAllShift();  
  19.         dgvcolshift.DisplayMember = "MyName";  
  20.         dgvcolshift.ValueMember = "MyKeyId";  
  21.         dgvcolshift.DataPropertyName = "Shift";  
  22.   
  23.         _Breaks=Break.GetAllBreak();  
  24.         dgvBreak.AutoGenerateColumns = false;  
  25.         dgvBreak.DataSource = _Breaks;  
  26.     }  

that's code for getAllBreaks

  1. public static List<Break> GetAllBreak()  
  2.     {  
  3.         return new ContexManager().Breaks.Where(c => c.MyKeyId != 0).Include(c => c.Machine).Include(c => c.Employee).Include(c => c.Shift).ToList();  
  4.     }  

now when it runned in cells of shift it shown classLibrary.classes.shift for machine , employee such as shift what i have to do for it ?



 
 
 
 

Answers (3)