Window桌面表单下拉绑定问题

时间:2018-11-23 07:39:12

标签: c# winforms desktop-application

这是我用来绑定Movie DropDown的代码。在数据源中,我有两个数据用于绑定dropdown,movie dropdown在页面加载事件级别绑定,但抛出错误异常,如Image中所示: enter image description here

public void BindMovie(string date)
{
    try
    {
        MovieBAL objAccountBAL = new MovieBAL();
        drpMovie.DataSource = objAccountBAL.GetMovieByDate(date).ToList();
        drpMovie.ValueMember = "Id";
        drpMovie.DisplayMember = "MovieName";             
    }
    catch (Exception ex)
    {
        ELog.Write(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
}

1 个答案:

答案 0 :(得分:1)

public void BindMovie(string date)
        {
            try
            {
                MovieBAL objAccountBAL = new MovieBAL();
                drpMovie.ValueMember = "Id";
                drpMovie.DisplayMember = "MovieName";             
                drpMovie.DataSource = bjAccountBAL.GetMovieByDate(date).ToList();

            }
            catch (Exception ex)
            {
                ELog.Write(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
  • 为解决此问题,我在分配后最后分配了数据源 'ValueMember'和'DisplayMember'