2016-05-12 15 views
0

私はDataGridViewに「プログラム」で追加したDataGridViewRowを持っています。私は細胞の1つをDataGridViewButtonCellにしたいのでクリックしてください。 (私はのon_clickのdatagridviewのハンドラを持つことができますが、コードの単純化のためにこの方法を使いたいと思います)。クリック時のDataGridViewButtonCellボタンの色の変更

DataGridViewButtonCellのフォアカラー/バックカラーを設定したいと考えています。

DataGridViewRow dgvRow = new DataGridViewRow(); 
dgvRow = (DataGridViewRow)dgv.Rows[0].Clone(); 
dgvRow.Cells[0].Value = filename; 
dgvRow.Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; 

DataGridViewButtonCell dgvBtn = new DataGridViewButtonCell(); 
dgvRow.Cells[1].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; 
dgvBtn.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; 

dgvBtn.Style.BackColor = Color.Green; //this sets the color of the cell, not the button in the cell. 

Q:セルに表示されるボタンの色を設定するにはどうすればよいですか?かなり多くのあなたがBackColorを変更することFlatStyleButtonようにする必要があり、通常のButtonと同様

答えて

1

dgvBtn.FlatStyle = FlatStyle.Flat; 
dgvBtn.Style.BackColor = Color.LightGreen; 
関連する問題