0

I have a Datagridview that has some text box columns.In this Datagridview I have added a DataGridViewButtoncolumn after the third column and I have set it as visible = false as shown in below code.

DataGridViewButtonColumn btnEllipse = new DataGridViewButtonColumn();

btnEllipse.Text = "...";
btnEllipse.FillWeight = 6;
btnEllipse.MinimumWidth = 20;
btnEllipse.Width = 20;
btnEllipse.DividerWidth = 0;
//btnCompanyProperty.HeaderText = "To Company/Property";
btnEllipse.UseColumnTextForButtonValue = true;
dgvForecast.Columns.Insert(4, btnEllipse);
dgvForecast.Columns[4].Visible = false;
dgvForecast.Columns[dgvForecast.Columns["BaseValue"].Index + 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

dgvForecast.Columns[dgvForecast.Columns["BaseValue"].Index + 1].Width = 20;
dgvForecast.Columns["BaseValue"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;

dgvForecast.Columns["BaseValue"].CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight;

Now My problem is that I have to show only this button cell when i click on index 3 cell.Now this is showing full Button column when i click on index 3 cell as shown in below image.I only want to show selected row button cell not full Button Column.

enter image description here

I want that when i click on first row value cell only first row Button cell should be visible and when i click on second row value cell first row button should be invisible and current row button should be visible.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Amit Kumar
  • 1,059
  • 3
  • 22
  • 43

1 Answers1

0

You can't hide specific cells in the DataGridView. There is no direct support for this in the DataGridView.

One way of doing this is to create custom DataGridViewButtonColumn to control the visibility using a custom property and override the paint method to draw a rectangle with the background color when this property is set. It is similar to that available in the msdn forum question removehide-button-on-datagridview.

Using the above custom column you could make the cell visible in CellEnter/RowEnter event and hide it in CellLeave/RowLeave event.

Junaith
  • 3,298
  • 24
  • 34