通过 DataGridView.CellParsing 事件可以设定用户输入的值。下面的示例:当输入英文文本内容的时候,立即被改变为大写。 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

[VB.NET]
'CellParsing 事件处理方法
Private   Sub  DataGridView1_CellParsing( ByVal  sender  As   Object , _
        
ByVal  e  As  DataGridViewCellParsingEventArgs) _
        
Handles  DataGridView1.CellParsing
    
Dim  dgv  As  DataGridView =  CType (sender, DataGridView)

    
' 单元格列为 “Column1”
     If  dgv.Columns(e.ColumnIndex).Name = "Column1"  AndAlso  _
            e.DesiredType 
Is   GetType ( String Then
        
' 将单元格值设为大写
        e.Value = e.Value.ToString().ToUpper()
        
' 解析完毕
        e.ParsingApplied =  True
    
End   If
End Sub

 

[C#]
//CellParsing 事件处理方法
private   void  DataGridView1_CellParsing( object  sender,
    DataGridViewCellParsingEventArgs e)
{
    DataGridView dgv = (DataGridView)sender;

    
// 单元格列为 “Column1”
     if  (dgv.Columns[e.ColumnIndex].Name == "Column1" &&
        e.DesiredType == 
typeof ( string ))
    {
        
// 将单元格值设为大写
        e.Value = e.Value.ToString().ToUpper();
        
// 解析完毕
        e.ParsingApplied =  true ;
    }
}