■■■

2016年3月31日木曜日

DataGridViewでセルの値をフォーマットする方法

DataGridViewでセルの値をフォーマットする方法
VB.NET
Private Sub dgv1_CellFormatting(ByVal sender As Object, _
ByVal e As DataGridViewCellFormattingEventArgs) _
Handles dgv1.CellFormatting
Dim dgv As DataGridView = CType(sender, DataGridView)

If dgv.Columns(e.ColumnIndex).Name = "col1" AndAlso _
TypeOf e.Value Is String Then
Dim strA As String = e.Value.ToString()
e.Value = strA.ToUpper()
e.FormattingApplied = True
End If
End Sub
C#
private void dgv1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
DataGridView dgv = (DataGridView)sender;

if (dgv.Columns[e.ColumnIndex].Name == "col1" && e.Value is string)
{
string strA = e.Value.ToString();
e.Value = strA.ToUpper();
e.FormattingApplied = true;
}
}
















■■■