What caused my DGW's paint event as failure

Socarsky

Well-known member
Joined
Mar 3, 2014
Messages
59
Programming Experience
Beginner
Below event works fine but another thing causes its task runs 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);
                    }

                }
            }
        }


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));
        
        }


and last one is a method for setting DGW.
private void SetupDGWStop() 
        {
            this.Controls.Add(DGWSTOP);
            DataGridViewCellStyle style = DGWSTOP.ColumnHeadersDefaultCellStyle;
            style.BackColor = Color.Navy;
            style.ForeColor = Color.White;
            style.Font = new Font(DGWSTOP.Font, FontStyle.Bold);

            DGWSTOP.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
            DGWSTOP.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.True;
            DGWSTOP.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
            DGWSTOP.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            DGWSTOP.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            DGWSTOP.RowHeadersVisible = true;
            DGWSTOP.GridColor = SystemColors.ActiveBorder;
            DGWSTOP.Font = new Font("Franklin Gothic Book", dgwPersonnel.DefaultCellStyle.Font.Size * 1 * 1F, FontStyle.Regular, GraphicsUnit.Point);
            DGWSTOP.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            DGWSTOP.MultiSelect = false;
            DGWSTOP.BackgroundColor = Color.Honeydew;
        }
 
I just deactivated to call DGWSTOP_RowPostPaint event but it does not change the matter with a good result which I expected to get. The case stand still. The DGW does not show <No data to display> even its row count 0. I also removed SetupDGWStop method to run but the matter is still the same.
 
Back
Top Bottom