Kai Kai - 1 year ago 205
C# Question

DataGridView button text not appearing despite UseColumnTextForButtonText set to true

I've added a button column to a DataGridView and want to display the text "Compare" on it. I've set the

property to Compare and
to True, but no text displays:

Properties set, no text visible

This is also true at runtime, so it's not just not displaying in the designer:

No text at runtime either

How do I get the text to appear?

Edit: For prosperity's sake, here's the code in the generated Designer.cs file. I haven't added any code to this form myself yet, so there's no chance that something's resetting it further down the line.

// Compare
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Calibri", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Compare.DefaultCellStyle = dataGridViewCellStyle1;
this.Compare.HeaderText = "Compare";
this.Compare.Name = "Compare";
this.Compare.Text = "Compare";
this.Compare.ToolTipText = "Compare the dictionary definition to the system definition";
this.Compare.UseColumnTextForButtonValue = true;

Kif Kif
Answer Source

DataGridViewButtonColumn does not display the text in the button on the last row. Since in your example you only display one row, it is not shown. Add some more rows, and the text will appear in all but the last row.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download