如何将列表绑定到DataGridView Win窗体

时间:2014-02-09 02:32:50

标签: c# winforms datagridview

我有以下代码,但DataGridView向我显示空行。我找不到解决方案。我究竟做错了什么?这是代码:

namespace Domain.Repository
{
    public class JenisTransaksi_Repository
    {
        #region Private Variables
        private Int64 _Id_JenisTransaksi1 { get; set; }
        private string _Kode_JenisTransaksi1 { get; set; }
        private string _Nama_JenisTransaksi1 { get; set; }
        #endregion                

        #region Load Data
        public List<JenisTransaksi_Repository> RetrieveAllJenisTransaksi()
        {
            using (var _Ent = new DB_INVENTORYEntities())
            {
                List<JenisTransaksi_Repository> _List = new List<JenisTransaksi_Repository>();
                _List = (from x in _Ent.Tb_JenisTransaksi
                 select new JenisTransaksi_Repository
                 {
                     _Id_JenisTransaksi1 = x.Id_JenisTransaksi,
                     _Kode_JenisTransaksi1 = x.Kode_JenisTransaksi,
                     _Nama_JenisTransaksi1 = x.Nama_JenisTransaksi
                 }).ToList();

                return _List;
            }
        }
    }
}

绑定到网格:

#region Bind To Grid
public void BindAllJenisTransaksi(DataGridView _DataGridView)
{
     var bindingList = new BindingList<JenisTransaksi_Repository>(RetrieveAllJenisTransaksi());
     var source = new BindingSource(bindingList, null);
     _DataGridView.DataSource = source;
}
#endregion

0 个答案:

没有答案