2013-04-22 62 views
0

我用這個代碼片斷設置DataGridViewComboBoxCell的顏色?

// Second Column: Hand to use 
DataGridViewComboBoxCell handToUseCell = (DataGridViewComboBoxCell)this._robotSelectionDataGridView[Common.SECOND_COLUMN, currentRow]; 
handToUseCell.Items.Clear(); 
foreach (Hand hand in robotInfo.Hands) 
{ 
    handToUseCell.Items.Add(hand.Name.ToString()); 
} 
handToUseCell.DisplayStyle = (handToUseCell.Items.Count > 1) ? DataGridViewComboBoxDisplayStyle.ComboBox : 
                DataGridViewComboBoxDisplayStyle.Nothing; 
handToUseCell.Value = handToUseCell.Items[0]; 
handToUseCell.Style.BackColor = Color.DimGray; 

但背部顏色沒有變化。當我設置cell.style.backcolor時會發生什麼?

+0

您是否嘗試爲下拉菜單或元素(如圖所示)設置背景顏色? – 2013-04-22 10:57:34

+0

我試圖添加backcolor到下拉菜單。 – Vidhya 2013-04-22 10:58:48

+0

@Vidhya你試圖在Windows應用 – 2013-04-22 14:06:48

回答

0

嘗試以下

handToUseCell.DefaultCellStyle.BackColor = Color.Red;

handToUseCell.CellStyle.BackColor = Color.Red;

讓我知道結果.. 希望它能幫助。

+0

DataGridViewComboBoxCell沒有「DefaultCellStyle」和「CellStyle」屬性。 – Vidhya 2013-04-22 11:07:01

+0

嘗試引用此文檔... http://msdn.microsoft.com/en-IN/library/z2akwyy7.aspx讓我知道它是否有幫助.. – 2013-04-22 11:22:58