我想創建一個自定義的DataGridViewRow作爲分隔符(將數據分成組)。我做到了通過重寫的DataGridViewRow類的PainCells方法是這樣的:自定義DataGridViewRow問題
protected override void PaintCells(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow, DataGridViewPaintParts paintParts)
{
graphics.FillRectangle(new SolidBrush(BackgroundColor),rowBounds);
StringFormat format = new StringFormat {Alignment = StringAlignment.Center,LineAlignment = StringAlignment.Center};
graphics.DrawString(Text, this.DataGridView.Font, new SolidBrush(ForeColor), rowBounds,format);
}
凡文字,BACKGROUNDCOLOR和前景色是我SeparatorDataGridViewRow類的屬性。這些排看起來完全像我想要的那樣。但是這只是「覆蓋」,因爲在繪製的矩形下面仍然有原始的datagrid單元格。特別是與我添加的刪除按鈕形式DataGridViewButtonColumn單元格。因爲如果我點擊按鈕是我的分隔符行被刪除的單元格。
我不認爲這是達到我要存檔的正確方法,所以我會很高興如果你們可以向我展示正確的方向或告訴我可以用這種解決方案做什麼來阻止用戶可能性做無論什麼是「在繪製的rectagle下面」的任何東西。
我幾乎沒有創建自定義控件的經驗,所以我不知道要重寫什麼方法或要添加什麼來實現特定目標。 每個幫助讚賞:)
有什麼辦法可以告訴DataGridView不要在給定的行中繪製單元格。或者在給定類型的行中?我找不到任何方法對此負責。 DataGridView的onPaint方法只給出了ClipRectangle和Graphics作爲參數,所以我不能確定他正在繪製哪一行。 – Brazol