残念ながら、テキストを希望どおりにフォーマットするための標準プロパティはありません。
さまざまな DGV イベントを使用してテキストの書式を設定したくない場合は、いつでも独自の DGV コンポーネントを作成して、標準の DGV コンポーネントの代わりにそれらを使用することができます。 MSDN のこの記事から始めてください。
編集
これは、HanSolo と名乗る人のブログ エントリで、必要なことを行っています。
コードは次のとおりです。
public class DataGridViewUpperCaseTextBoxColumn : DataGridViewTextBoxColumn {
public DataGridViewUpperCaseTextBoxColumn() : base() {
CellTemplate = new DataGridViewUpperCaseTextBoxCell();
}
}
public class DataGridViewUpperCaseTextBoxCell : DataGridViewTextBoxCell {
public DataGridViewUpperCaseTextBoxCell() : base() { }
public override Type EditType {
get {
return typeof(DataGridViewUpperCaseTextBoxEditingControl);
}
}
}
public class DataGridViewUpperCaseTextBoxEditingControl : DataGridViewTextBoxEditingControl {
public DataGridViewUpperCaseTextBoxEditingControl() : base() {
this.CharacterCasing = CharacterCasing.Upper;
}
}
このコードをプロジェクトに含めます。これを行うと、DataGridViewUpperCaseTextBoxColumn 型の DataGridView に新しい DataGridViewColumn を追加できるようになります。この新しい DataGridViewColumn は、列の TextBox コンポーネントに入力されたすべてのテキストを大文字にします。
また、イベントを使用しないという決定を再検討する必要があります。やり方はとても簡単です。たとえば、dataGridView1 という名前の DGV がある場合、次のように CellFormatting イベントを使用できます。
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
// Check the value of the e.ColumnIndex property if you want to apply this formatting only so some rcolumns.
if (e.Value != null) {
e.Value = e.Value.ToString().ToUpper();
e.FormattingApplied = true;
}
}