2

我对组合框有疑问

    private void Form_AddGoal_Load(object sender, EventArgs e)
    {  
        LoadGoal();
        IList<Perspective> perspectives = PerspectiveRepository.All(); // I get all perspectives

        CBPerspective.DataSource = perspectives;
        CBPerspective.DisplayMember = "Name";

        // Here I initialize other components
    }

    private void LoadGoal()
    {
        if (Goal== null)
            Goal = new Goal();

        // Here I bind other components

        CBPerspective.DataBindings.Add("SelectedItem", Goal, "Perspective");   
    }

    public void SaveBtn_Click(object sender, EventArgs e)
    {
          // I save the Goal
    }

当表单打开时,一切正常。如果我没有在组合框中选择任何选项(即第一个选项保留它)并且我将数据保存在 Perspective 属性为 null 的表单上,但如果我在组合框中选择其他选项并以相同的方式继续,透视图等于所选项目,因此可以完美运行。到底是怎么回事?我需要触发事件吗?

4

0 回答 0