2013-06-12 37 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