Hi friend.
(WinForm)
I need to create a custom space between Columns header's row and the first row of the datagridview . in C# 2010 (Win Form) . so that i'll be able to put some controls in the created space .
I create a new Class (inherited from DataGridViewRow) and overrided the OnPaint() method of the Base class . But it only Shift the rows Down and when i click on one of the shifted down rows (In DataGridView at run time) it never display the row in correct format and colors.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Collections;
using System.Reflection;
namespace DRC.Controls
{
class Class1Row : DataGridViewRow
{
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, int rowIndex, DataGridViewElementStates rowState, bool isFirstDisplayedRow, bool isLastVisibleRow)
{
rowBounds = new Rectangle(rowBounds.X, rowBounds.Y+22, rowBounds.Width, rowBounds.Height);
clipBounds = new Rectangle(clipBounds.X, clipBounds.Y + 22, clipBounds.Width, clipBounds.Height);
base.Paint(graphics, clipBounds, rowBounds, rowIndex, rowState, isFirstDisplayedRow, isLastVisibleRow);
}
}
}
This is the picture of my work and what i need .
http://hospitalaria.ir/Resource/UploadFiles/Gallery/orginal/eq5ogcht.ufd.jpg
This is the picture of my problem and what i need to be solved .
http://hospitalaria.ir/Resource/UploadFiles/Gallery/orginal/pies2y5t.54d.jpg
And in My owen DataGridView
I wrote this codes
public partial class DRCDataGridView : DataGridView
{
public DRCDataGridView()
{
InitializeComponent();
RowTemplate = new Class1Row();
}
public DRCDataGridView(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
Rectangle ClipRectangle = new Rectangle(pe.ClipRectangle.X, pe.ClipRectangle.Y + 22, pe.ClipRectangle.Width, pe.ClipRectangle.Height);
PaintEventArgs p = new PaintEventArgs(pe.Graphics, ClipRectangle);
base.OnPaint(pe);
}
protected override void OnRowPrePaint(DataGridViewRowPrePaintEventArgs e)
{
e.ClipBounds = new Rectangle(e.ClipBounds.X, e.ClipBounds.Y + 22, e.ClipBounds.Width, e.ClipBounds.Height);
base.OnRowPrePaint(e);
}
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
{
e.ClipBounds = new Rectangle(e.ClipBounds.X, e.ClipBounds.Y + 22, e.ClipBounds.Width, e.ClipBounds.Height);
base.OnRowPostPaint(e);
}
protected override void OnCellBeginEdit(DataGridViewCellCancelEventArgs e)
{
base.OnCellBeginEdit(e);
}
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
Rectangle Clipbound = new Rectangle(e.ClipBounds.X,e.ClipBounds.Y+22,e.ClipBounds.Width,e.ClipBounds.Height);
Rectangle CellBound = new Rectangle(e.CellBounds.X, e.CellBounds.Y+22, e.CellBounds.Width, e.CellBounds.Height);
DataGridViewCellPaintingEventArgs k = new DataGridViewCellPaintingEventArgs(this, e.Graphics, Clipbound, CellBound, e.RowIndex, e.ColumnIndex, e.State, e, e, "", e.CellStyle, e.AdvancedBorderStyle, e.PaintParts);
base.OnCellPainting(k);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
}
protected override void OnColumnAdded(DataGridViewColumnEventArgs e)
{
base.OnColumnAdded(e);
}
}
Please Help .