DataGridView Button Text

  • Thread starter Thread starter Saimvp
  • Start date Start date
S

Saimvp

Hello and Gud Day.

I have a simple problem but I can't solve about the DataGridViewButtonColumn.
How can I show my Caption in DRV button.

Theres 2 way.

1. In the Design View. I set all the necessary needed like the "
UseColumnTextForButtonValue = true; "

2. Thru run time. Below is my sample code.

DataGridViewButtonColumn drv = new DataGridViewButtonColumn();

drv.HeaderText = "Sayre";
drv.UseColumnTextForButtonValue = true;
drv.DataPropertyName = "Sayre";
drv.DisplayIndex = 0;
drv.Text = "Sayre";
grid.Columns.Add(drv);

Result: None of these can show the caption "Sayre" in my Grid button.

Please help me.

Thanks.
 
Very odd; a quick test shows it working fine... this probably doesn't
help much, but it *should* work...

Marc

using System.ComponentModel;
using System.Windows.Forms;

class Foo
{
public string Bar { get; set; }
}
class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form
{
Controls = {
new DataGridView
{
Dock = DockStyle.Fill,
DataSource = new BindingList<Foo>
{
new Foo {Bar="abc"},
new Foo {Bar="def"}
},
Columns =
{
new DataGridViewButtonColumn
{
HeaderText = "Header",
UseColumnTextForButtonValue = true,
DataPropertyName = "Bar",
DisplayIndex = 0,
Text = "Button Text"
}
}
}
}
});
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top