Below event works fine if its tried to use in a simply implemented DGW, but another event's line of code or method causes its task failure. Here is the DGW paint event. if things goes well then DGW must show a string in the center of its as<No data to display>
private void DGWSTOP_Paint(object sender, PaintEventArgs e)
{
if (DGWSTOP.RowCount == 0)
{
using (SolidBrush brsh = new SolidBrush(Color.DarkBlue))
{
using (StringFormat strFormat = new StringFormat())
{
Font drawFont = new Font("Arial", 9);
strFormat.Alignment = StringAlignment.Center;
e.Graphics.DrawString("<No data to display>", drawFont, brsh, Convert.ToSingle(DGWSTOP.Left + (DGWSTOP.Width / 2)), Convert.ToSingle(DGWSTOP.Top + (DGWSTOP.Height / 2)), strFormat);
}
}
}
}Above event works fine, but below both or either cause failure the string appearance in center of DGW if there is no row.
The other event which is for drawing number in row header:
private void DGWSTOP_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
string strRowNumber = (e.RowIndex + 1).ToString();
while (strRowNumber.Length < DGWBase.RowCount.ToString().Length)
{
strRowNumber = "0" + strRowNumber;
}
SizeF size = e.Graphics.MeasureString(strRowNumber, DGWBase.Font);
if (DGWBase.RowHeadersWidth < (int)(size.Width + 20))
{
DGWBase.RowHeadersWidth = (int)(size.Width + 20);
}
Brush b = SystemBrushes.ControlText;
e.Graphics.DrawString(strRowNumber,
DGWBase.Font, b,
e.RowBounds.Location.X + 15,
e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
}