Click here to Skip to main content
15,909,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys.

I have a datagridview that display the student ID, student Name and gradelevel and 2 columns with header text as Final Grade and Remarks. Now, if the user inputs the final grades for the student at Column Final Grade, the Column Remarks will automatically display if the student is Passed or Failed. What I have done is adding the final grade in datagridview but I cannot do the latter part. Can anyone help me? Thanks in advance.


EXAMPLE:

StudentID||StudentName||GradeLevel||FinalGrade||Remarks
-------------------------------------------------------
20110876||John Lee||1||89||Passed
---------------------------------
20110877||Pete Low||1||75||Passed
---------------------------------
20110878||Chris Tiu||1||74||Failed
Posted

1 solution

Sounds like you need to handle a text changed event on the cell or the CellStateChanged event on the gridview.

I prefer the CellStateChanged as it does calculations after pressing enter (cell loses focus).

This assumes the name of the FinalGrade column is FinalGrade, not just the text.
C#
private void CellChanged(object sender, DataGridViewCellStateChangedEventArgs e) {
    if (e.Cell.OwningColumn.Name == "FinalGrade") {
        if (null != e.Cell.Value) {
            int score = 0;
            if (int.TryParse(e.Cell.Value.ToString(), out score)) {
                // dgv1 is your data grid view.
                DataGridViewCell cell = dgv1.Rows[e.Cell.RowIndex].Cells["Remarks"];
                if (null != cell) {
                    if (score >= 75) {
                        cell.Value = "Passed";
                    }
                    else {
                        cell.Value = "Failed";
                    }
                }
            }
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900