Adding a button column to a DataGridView, but it will not be displayed

I am adding a button column in a datagridview for a databatview. The column is created and the button is available, but in fact it is not displayed. It is difficult to explain, so I post a screenshot below.

Here is 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:

Screen shot

+4
source share
1 answer

You need to do this when you define button properties.

 btnDelete.UseColumnTextForButtonValue = true; 
+8
source

Source: https://habr.com/ru/post/1338937/


All Articles