1
我有一個自定義的ComboBox
控件,我想在DataGridViewCell
中使用。我首先繼承了DataGridViewCell
,並試圖覆蓋Paint()
方法在單元格中繪製ComboBox
。如何在DataGridViewCell中繪製自定義組合框?
我的問題是,在繼承DataGridViewColumn
並將CellTemplate
屬性設置爲我的CustomDataGridViewCell
類的新實例後,該單元格變爲灰色且沒有內容。
cBox
類變量在對象ctor中實例化。
protected override void Paint(Graphics graphics, Rectangle clipBounds,
Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
object value, object formattedValue, string errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle borderStyle,
DataGridViewPaintParts paintParts)
{
// Call MyBase.Paint() without passing object for formattedValue param
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value,
"", errorText, cellStyle, borderStyle, paintParts);
// Set ComboBox properties
this.cBox.CheckOnClick = true;
this.cBox.DrawMode = System.Windows.Forms.DrawMode.Normal;
this.cBox.DropDownHeight = 1;
this.cBox.IntegralHeight = false;
this.cBox.Location = new System.Drawing.Point(cellBounds.X, cellBounds.Y);
this.cBox.Size = new System.Drawing.Size(cellBounds.Width, cellBounds.Height);
this.cBox.ValueSeparator = ", ";
this.cBox.Visible = true;
this.cBox.Show();
}
如何正確地在單元格中繪製ComboBox
?
Hi.Could您提供文件在DataGridView中有一個CheckedCombBox? – San 2011-04-26 07:34:36