データベースの値がバインドされているグリッドビューがあります。次のように、各行のセルの 1 つに値が格納されています。
1
2
3
4
これらの値をデータベースではなく、表示されているものだけに変更する最善の方法は何でしょうか
Q1
中年
Q3
年末年始
データベースの値がバインドされているグリッドビューがあります。次のように、各行のセルの 1 つに値が格納されています。
1
2
3
4
これらの値をデータベースではなく、表示されているものだけに変更する最善の方法は何でしょうか
Q1
中年
Q3
年末年始
みんなありがとう、でも私はこれを使ってそれを手に入れることができました:
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;
}
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