Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding button column to DataGridView but it won't show

I'm adding a button column to my databound datagridview. The column gets created, and the button is clickable, but it doesn't really show. Its kinda hard to explain so I'm posting a screenshot below.

Here's the code

        private void LoadDataGridView()
        {
            dgvClients.DataSource = null;
            dgvClients.DataSource = Clients;

            DataGridViewButtonColumn btnDelete = new DataGridViewButtonColumn();
            btnDelete.Name = "btnDelete";
            btnDelete.Text = "Delete";
            btnDelete.HeaderText = "Delete";
            dgvClients.Columns.Add(btnDelete);

            //set column sizes. Total width of dgv w/o scrollbar is 544
            dgvClients.Columns[0].Width = 100;
            dgvClients.Columns[1].Width = 344;
            dgvClients.Columns[2].Width = 100;
            dgvClients.Columns[3].Width = 100;


            dgvClients.Show();
            dgvClients.ClearSelection();
        }

Screenshot:

Screenshot

like image 464
xbonez Avatar asked Feb 25 '23 03:02

xbonez


1 Answers

You need to do this when you define the button's properties.

btnDelete.UseColumnTextForButtonValue = true;
like image 134
Yetti Avatar answered Feb 27 '23 16:02

Yetti