将datagridview中的负值转换为括号

时间:2017-08-30 15:19:33

标签: vb.net datagridview

我有这个代码试图将datagridview中的负值转换为括号。

例如:如果单元格值为" -3",则datagridview应显示"(3)"

这是我的代码:

Private Sub LoadDATAGRIDVIEWDataSUBJECTS()
    sqlCon.Open()
    Try
        Dim QUERY As String
        QUERY = "SELECT ListofSubjects.[Course No.], Curriculum.[Lab.] + Curriculum.[Lec.] " &
                "FROM StudentAcademicRecords INNER JOIN SREGStudentInformation ON StudentAcademicRecords.StudentID = SREGStudentInformation.ID INNER JOIN [Class Schedule LINE] ON StudentAcademicRecords.[Subject Code] = [Class Schedule LINE].SchedID INNER JOIN Curriculum ON [Class Schedule LINE].[Subject Code] = Curriculum.[Subject Code] INNER JOIN ListofSubjects ON Curriculum.SubjectID = ListofSubjects.SubjectID INNER JOIN CourseOfferings ON StudentAcademicRecords.Course = CourseOfferings.CourseID AND Curriculum.CourseID = CourseOfferings.CourseID INNER JOIN SchoolYear ON StudentAcademicRecords.[Academic Year] = SchoolYear.[SY ID] INNER JOIN SemesterList ON StudentAcademicRecords.Period = SemesterList.SemID AND Curriculum.SemesterID = SemesterList.SemID " &
                "WHERE (SREGStudentInformation.[Student ID] = '" & cmbStudentID.Text & "') AND (SemesterList.[Sem.] = '" & cmbSemester.Text & "') AND (SchoolYear.[School Year] = '" & cmbSchoolYear.Text & "')"

        CMD = New SqlCommand(QUERY, sqlCon)
        Reader = CMD.ExecuteReader

        DTable.Load(Reader)
        dgvSubjects.DataSource = DTable

        dgvSubjects.Columns(1).HeaderText = "Units"
        dgvSubjects.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        dgvSubjects.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

    Reader.Close()
    sqlCon.Close()
    LoadOtherInfo()

    For Each row As DataGridViewRow In dgvSubjects.Rows
        If row.Cells(1).Value < 0 Then
            row.Cells(1).Value = FormatNumber((row.Cells(1).Value), 0, UseParensForNegativeNumbers:=TriState.True)
        End If
    Next

但问题是,我收到了这个错误。如果您想介绍一下图片: Datagridview Error

我该如何解决这个问题?谢谢你的帮助

0 个答案:

没有答案