0

我试图为它解决近 4 个小时,但我找不到任何解决方案

public class FinalClassScoreModel
{
    private readonly FinalClassScore _finalClassScore;

    public FinalClassScoreModel(FinalClassScore finalClassScore)
    {
        this._finalClassScore = finalClassScore;
    }

    public int EnrollId
    {
        get
        {
            return this._finalClassScore.EnrollId;
        }
    }

    public string StudentNo
    {
        get
        {
            return this._finalClassScore.Enroll.Student.StudentNo;
        }
    }

    public string ReversedName
    {
        get
        {
            return this._finalClassScore.Enroll.Student.ReversedName;
        }
    }

    public decimal? Prelim
    {
        get
        {
            return this._finalClassScore.Prelim;
        }
    }

    public string PrelimE
    {
        get
        {
            return this._finalClassScore.PrelimE;
        }
    }

    public decimal? Midterm
    {
        get
        {
            return this._finalClassScore.Midterm;
        }
    }

    public string MidtermE
    {
        get
        {
            return this._finalClassScore.MidtermE;
        }
    }

    public decimal? Final
    {
        get
        {
            return this._finalClassScore.Final;
        }
    }

    public string FinalE
    {
        get
        {
            return this._finalClassScore.FinalE;
        }
    }

    public decimal? FinalGrade
    {
        get
        {
            return this._finalClassScore.FinalGrade;
        }
    }


    public bool IsDropped
    {
        get
        {
            return this._finalClassScore.Enroll.IsDropped;
        }
    }

    public bool IsIncomplete
    {
        get
        {
            return this._finalClassScore.Enroll.IsIncomplete;
        }
    }

    public bool IsGradeSubmitted
    {
        get
        {
            return this._finalClassScore.Enroll.IsGradeSubmitted;
        }
    }


Public Property FinalClassScoreModels() As IEnumerable(Of FinalClassScoreModel) Implements IAlternativeView.FinalClassScoreModels
        Get
            Return Me._finalClassScoreModels
        End Get
        Set(ByVal value As IEnumerable(Of FinalClassScoreModel))
            If DesignMode Then Exit Property
            Me._finalClassScoreModels = value
            Me.dgrAlternativeGrades.DataSource = Me._finalClassScoreModels
        End Set
    End Property

起初还可以,但是当我删除 FinalClassScoreModelList 上的 1 个数据并重新运行时,它Me.dgrAlternativeGrades.Datasource = Me._finalClassScoreModels会抛出nullreference exception

public string StudentNo
    {
        get
        {
            return this._finalClassScore.Enroll.Student.StudentNo;
        }
    }

顺便说一句,如果我没有设置datapropertyname每列的,它不会出错,datagridview但我需要设置它,因为我不想自动生成列。

我的项目是 vb.net 和 C# 的组合

4

1 回答 1

0

对于那些也会遇到这个问题的初学者,我在 FinalClassScoreModel 课上做了什么

public class FinalClassScoreModel
{
    private readonly FinalClassScore _finalClassScore;
    private readonly Enroll _enroll;

    public FinalClassScoreModel(FinalClassScore finalClassScore, Enroll enroll)
    {
        this._finalClassScore = finalClassScore;
        this._enroll = enroll;
    }

    public int EnrollId
    {
        get
        {
            return this._finalClassScore.EnrollId;
        }
    }

    public string StudentNo
    {
        get
        {
            return this._enroll.StudentNo;
        }
    }

这样,即使它是否为空,它也只会获得 ot StudentNo 的值

谢谢大家

于 2013-09-03T06:29:27.753 回答