Gridview,改变可见值
本文关键字:改变 Gridview | 更新日期: 2023-09-27 18:17:58
我有一个gridview从数据库的值被绑定到。在每行中存储一个单元格的值如下:
1 23
4最好的方法是不更改数据库中的值,而只更改查看到
的值。Q1
年中期第三季
结束年
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
您可以在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
谢谢大家,但我能够得到它使用这个:
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;
}