私はDataGridView
を持っていて、そのRowPostPaint
イベント中に各行の最初のセルにTreeViewスタイルの点線を描画しています。最初のセル(DataGridViewTextBoxCell
)が編集モードにあるとき、線は描画されません。編集コントロールのためのペイントはどうすればできますか?標準の編集コントロールにはPaintイベントがありません。そうしないと新しいタイプのセルを作成したくありません。DataGridViewの編集コントロールの描画をどのように処理するのですか?
答えて
カスタムセルタイプを作成し、Bryanが説明したように編集コントロールを縮小することで同様の問題を解決しました。非常に難しいことではありません。編集コントロールをすべての上に描画することを覚えている唯一の方法です。
このような何かがあなたのために働くべき:
public class PaintAccommodatingTextBoxCell : DataGridViewTextBoxCell
{
// Adjust the editing panel, so that custom painting isn't
// drawn over when cells go into edit mode.
public override Rectangle PositionEditingPanel(Rectangle cellBounds, Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
// First, let base class do its adjustments
Rectangle controlBounds = base.PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
// Shrink the bounds here...
return controlBounds;
}
}
public class PaintAccommodatingTextBoxColumn : DataGridViewTextBoxColumn
{
PaintAccommodatingTextBoxCell templateCell;
public PaintAccommodatingTextBoxColumn()
{
templateCell = new PaintAccommodatingTextBoxCell();
}
public override DataGridViewCell CellTemplate
{
get
{
return templateCell;
}
set
{
PaintAccommodatingTextBoxCell newTemplate = value as PaintAccommodatingTextBoxCell;
if (newTemplate == null)
throw new ArgumentException("Template must be a PaintAccommodatingTextBoxCell");
else
templateCell = newTemplate;
}
}
}
同じ問題に取り組んでいたのですが、単純に戻り値を変更するのではなく、cell.bufferパラメータを変更してbase.PositionEditingPanelを呼び出す必要があることがわかりました。それ以外の場合、EditingControlのサイズは変更されますが、カスタムセルペイントを覆い隠すEditingPanelは変更されません。 – asponge
左から16まで、あなたの最初の列の最初のセットセルのパディング、ビューモードまたは編集モードでは、コンテンツが与えられたパディングを使用して表示されますので。
this.dataGridView1.Columns[0].DefaultCellStyle.Padding= new Padding(16,0,0,0);
その後CellPainting
イベントを処理し、これらの手順を実行します。
- は、最初の列だけをペイントし、rowIndexには
- は、あなたのツリーラインをペイントしたり、 を好きなレンダリング列のヘッダーを避けるために> = 0でなければなりません
- e.Handled = trueを使用してデフォルトペイントをキャンセルします。
ここにコードがあります:
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
//Only paint rirst column and RowIndex should be >=0 to avoid rendering column header
if (e.ColumnIndex == 0 & e.RowIndex >= 0)
{
//Paint your tree lines or whatever you want
using (var treePen = new Pen(Color.Gray, 1))
{
treePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
e.Paint(e.CellBounds, DataGridViewPaintParts.All);
e.Graphics.DrawLine(treePen,
new Point(e.CellBounds.Left + 4, e.CellBounds.Top),
new Point(e.CellBounds.Left + 4, e.CellBounds.Bottom));
e.Graphics.DrawLine(treePen,
new Point(e.CellBounds.Left + 4, e.CellBounds.Top + e.CellBounds.Height/2),
new Point(e.CellBounds.Left + 12, e.CellBounds.Top + e.CellBounds.Height/2));
}
//Cancel default painting using e.Handled = true
e.Handled = true;
}
}
とここにスクリーンショットです:
私はそれを受け入れることができたらいいと思う。 –
- 1. どのようにdatagridview/datagridviewcellの編集コントロールを取得するには?
- 2. datagridviewの編集が困難です。どのように編集可能にするのですか?
- 3. FileUploadコントロールの編集を管理する
- 4. データ編集のセル編集後に更新を処理する
- 5. datagridviewコントロールのイベント処理について
- 6. OpenStreetmapは並行編集をどのように処理しますか?
- 7. Qt:ダミーライン編集コントロールを描画する方法
- 8. NSTableViewの編集の処理
- 9. DataGridViewでのカスタム編集コントロールの妥当性確認
- 10. WPFで大量のテキストを処理/編集するにはどうすればよいですか?
- 11. DataGridViewの下部にある編集行を削除するにはどうすればよいですか?
- 12. どのようにオートマトンを描画するのですか?
- 13. LoginStatusコントロールのクリックはどのように処理できますか?
- 14. 処理:xフレームごとにどのように描画すればよいですか?
- 15. asp.netの編集コントロール列と画像列をマージするにはどうすればいいですか?
- 16. コントロールはそのコントロールの外でマウスクリックをどのように処理できますか?
- 17. 複数の画像に編集ポストを処理する方法Asp.Net MVC
- 18. WinFormsのDataGridView編集セル
- 19. DataGridViewセル編集
- 20. DataGridView編集モード
- 21. コントロールの描画
- 22. 空のDataGridviewを処理するには?
- 23. どのようにSMTPタイムアウトを処理するのですか
- 24. どのようにUpdateExceptionを処理するのですか?
- 25. どのように画面に描画できますか?
- 26. 編集/追加/編集をするためにどのようにデータグリッド
- 27. スカラのネストマップ - どのように処理するのですか?
- 28. 編集/更新イベントの外にTextBoxコントロールにアクセスするにはどうすればよいですか?
- 29. aws lambdaでどのようにノードモジュールを編集しますか?
- 30. これをどのように編集できますか?
私は選択したセルにエクセルのようなグリフを追加しようとしながら、あなたとまったく同じ問題をヒットしました。編集コントロールを使用しているときに、ペイントイベントが呼び出されることはありません。現在、PositionEditingPanelプロパティを使用して編集コントロールを縮小し、親セルのグリフに干渉しないようにしています。私はそれを壊したら私はポストバックします。 – Bryan
@ブライアン:ありがとう。 – Simon