DataGridView button text not appearing despite UseColumnTextForButtonText set to true

你说的曾经没有我的故事 提交于 2019-12-10 10:16:14

问题


I've added a button column to a DataGridView and want to display the text "Compare" on it. I've set the Text property to Compare and UseColumnTextForButtonValue to True, but no text displays:

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

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;

回答1:


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.




回答2:


You can set "UseColumnTextForButtonValue", the text will be shown also for the last row then.




回答3:


Kif gets the right answer:

DataGridViewButtonColumn does not display the text in the button on the last row. Add some more rows, and the text will appear in all but the last row.

but if you wanna all shows the text you want(include the last row),you can simply realize the event handler CellValueChanged and set the cell value like this:

_yourDataGridView[Compare.Name, rowIndex].Value = "Compire";


来源:https://stackoverflow.com/questions/30256811/datagridview-button-text-not-appearing-despite-usecolumntextforbuttontext-set-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!