フォント サイズとスタイルを変更する必要がある DataGridView (WinForm アプリケーション) の列があります。ここの記事から: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.font.aspx、私は以下のコードが私が望む結果を得ると考えています(私は最初にスタイリングを変更してテストします):
this.dataGridViewMain.Columns[3].DefaultCellStyle.Font = new Font(dataGridViewMain.DefaultCellStyle.Font, FontStyle.Italic);
しかし、コードは何も変更しません。また、イベント ハンドラーにコードを追加しようとしましたRowPostPaint
が、まだ機能しません。プログラムで使用されるフォントがプロパティに設定されていることは知っていDataGridView.RowsDefaultCellStyle
ますが、イベントにコードを配置するRowPostPaint
とそれが上書きされると思いました。以下は、RowPostPaint
イベントのコードです。
void dataGridViewMain_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
this.dataGridViewMain.Columns[3].DefaultCellStyle.BackColor = Color.Gray;
foreach (DataGridViewRow row in this.dataGridViewMain.Rows)
{
int daysInShop = Convert.ToInt32(row.Cells["Days in the shop"].Value);
if (daysInShop > 4)
{
row.DefaultCellStyle.BackColor = Color.Red;
row.DefaultCellStyle.ForeColor = Color.White;
}
else if (daysInShop > 2)
{
row.DefaultCellStyle.BackColor = Color.Yellow;
}
else
{
row.DefaultCellStyle.BackColor = Color.YellowGreen;
}
row.Height = 35;
}
this.dataGridViewMain.CurrentCell = null; // no row is selected when DGV is displayed
}
どんな助けでも大歓迎です。ありがとう。