2013-06-12 65 views
0

我有一個數據庫中的值綁定到一個gridview。有如下是存儲在每個行中的單元中的一個值:Gridview,更改可見值

什麼會是最好的方法是改變這些值不數據庫但僅限於查看的內容

Q1

今年中期

Q3

結束年份

+0

只需查看rowdatabound事件或TemplateColumn類型即可。我認爲你可以用它們中的每一個來實現它。 –

回答

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; 
    } 
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

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