2016-07-21 43 views
0

Unselected Selected如何在選擇DataGridView.DefaultCellStyle時保留背景和前景色?

當選擇在DataGridView該行的行的背景顏色被覆蓋,並且用戶不能確定哪些狀態行是英寸

有沒有辦法不改變背景選擇行時的顏色?

+0

沒有,但你可以設置selectioncolors:'德faultCellStyle.SelectionBackColor = yourColor;'etc .. – TaW

+0

你成功了嗎?另外:除非您至少有所不同,否則用戶將如何看到所選的行狀態? – TaW

+0

@TaW我只是想讓所有的文字變成粗體。不,我還沒有成功。我將採取它的顏色,並添加到它,如果它的選擇,如果其取消選擇刪除顏色。所以它更黑或更輕。 – Ben

回答

1

您需要將SelectionXxxColors設置爲您爲行設置的顏色。

可以使用SelectionChanged事件樣式所選行:

private void dataGridView2_SelectionChanged(object sender, EventArgs e) 
{ 

    foreach (DataGridViewRow row in dataGridView2.SelectedRows) 
    { 
     row.DefaultCellStyle.SelectionBackColor = row.DefaultCellStyle.BackColor; 
     row.DefaultCellStyle.SelectionForeColor = SystemColors.ControlText; 
               // row.DefaultCellStyle.ForeColor; 
    } 
    foreach (DataGridViewRow row in dataGridView2.Rows) 
     row.DefaultCellStyle.Font = row.Selected ? 
      new Font(dataGridView2.Font, FontStyle.Bold) : dataGridView2.Font; 
} 

注1:如果可能的話,你應該設置SelectionXXXXColors當您爲您的所有行設定的常規顏色,只更改字體樣式時選擇更改..

注2:而不是SystemColors.ControlText當然你也可以使用DefaultCellStyle.ForeColor提供你實際上已經把它..

相關問題