0

我有一个gridview,来自数据库的值被绑定到。每行中存储有一个单元格的值,如下所示:

1

2

3

4

最好的方法是更改​​不在数据库中的那些值,而仅更改所查看的值

第一季度

年中

第三季度

结束年份

4

3 回答 3

0

您可以在 CellFormatting 活动中尝试...

Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
    Dim sHeader As String = DataGridView1.Columns(e.ColumnIndex).Name

    If ucase(sHeader) = "QUARTER" Then '-------> change this with yours
        If e IsNot Nothing Then
            If e.Value IsNot Nothing Then
                Try
                    Select case e.Value
                        Case 1 : e.Value = "Q1"
                        Case 2 : e.Value = "Mid Year"
                        Case 3 : e.Value = "Q2"
                        Case 4 : e.Value = "End Year"
                    End Select
                    e.FormattingApplied = True
                Catch ex As FormatException
                    e.Value = ""
                End Try
            End If
        End If
    End If

End Sub
于 2013-06-12T22:58:59.907 回答
0
dataGridView.Rows[0].Cells[0].Value = desiredValue
dataGridView.Rows[1].Cells[0].Value = desiredValue
dataGridView.Rows[2].Cells[0].Value = desiredValue
dataGridView.Rows[3].Cells[0].Value = desiredValue

或者你可以遍历它们。您可以像这样访问gridView的数据的个人和平nameOfGridView.Rows[desiredRow].Cells[desiredColumn].Value

于 2013-06-12T14:44:46.007 回答
0

谢谢大家,但我能够使用它来获得它:

    protected string QuarterConvert(object strValue)
    {
        string retString = "";

        switch (Convert.ToString(strValue))
        {
            case "1":
                retString = "Q1";
                break;
            case "2":
                retString = "Mid-Year";
                break;
            case "3":
                retString = "Q3";
                break;
            case "4":
                retString = "Year-End";
                break;
            default:
                break;

        }
        return retString;
    }
于 2013-06-13T13:40:27.530 回答