Datagridview - DrawString (Watermark)

2 Answers 17 Views
GridView
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Radek asked on 08 Aug 2025, 09:19 AM

Hello,

I want to add drawstring (watermark) to datagridview for some help information (for example: "double click to add new item" etc)

Can you help me?

 

 

2 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 11 Aug 2025, 11:20 AM

Hello Radek,

Thank you for your interest in our RadGridView control for WinForms.

If you want to display a message in the control, when it is empty, for example, you can use the following code:

this.radGridView1.TableElement.Text = "Grid is empty";

If you want to have the text position in a different place and customize it, you can draw a string using the Paint event:

this.radGridView1.Paint += RadGridView1_Paint;

private void RadGridView1_Paint(object sender, PaintEventArgs e)
{
    if (this.radGridView1.Rows.Count == 0)
    {
        string watermark = "Double click to add new item";
        using (Font font = new Font("Segoe UI", 12, FontStyle.Italic))
        using (Brush brush = new SolidBrush(Color.Red))
        {
            // Measure string size
            SizeF textSize = e.Graphics.MeasureString(watermark, font);

            // Calculate centered position
            float x = (this.radGridView1.ClientSize.Width - textSize.Width) / 2;
            float y = (this.radGridView1.ClientSize.Height - textSize.Height) / 2;

            // Draw the text
            e.Graphics.DrawString(watermark, font, brush, x, y);
        }
    }
}

This code will draw the string in the center. You could modify the location per your requirements.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Radek
Top achievements
Rank 2
Iron
Iron
Iron
answered on 11 Aug 2025, 11:58 AM | edited on 11 Aug 2025, 05:59 PM

Hello,

the code this.radGridView1.TableElement.Text = "Grid is empty"; not working probably because is set own back color (radGridView1.TableElement.BackColor = Color.FromKnownColor(KnownColor.AppWorkspace);

I use Paint event and it works.

Thank you.

Tags
GridView
Asked by
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Radek
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or