Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the demo I've just tried. It seems to work OK. The whole idea is <strong>You can't hide a particular cell in DataGridView</strong>. However you can make it hidden as a normal GUI engine will use when it wants to hide any control/element (I think so). You just customize it to paint the cell with the <code>BackgroundColor</code> of your <code>DataGridView</code>. Of course, to make it work, it's not such easy. Here is the code for you:</p> <pre><code>//First, you have to be sure the whole third column is Visible. //CellPainting event handler for your dataGridView1 private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex == 2)//This is the Column index you want to hide. { object o = e.RowIndex == -1 ? null : dataGridView1[e.ColumnIndex - 1,e.RowIndex].Value; if (o!=null &amp;&amp;!(bool)o || e.RowIndex == -1 || e.RowIndex == dataGridView1.RowCount - 1) { e.Graphics.FillRectangle(new SolidBrush(dataGridView1.BackgroundColor), e.CellBounds); if(e.RowIndex &gt; -1) dataGridView1[e.ColumnIndex, e.RowIndex].ReadOnly = true; e.Handled = true; } if (o != null &amp;&amp; (bool)o) { dataGridView1[e.ColumnIndex, e.RowIndex].ReadOnly = false; } } } //CellContentClick event handler for your dataGridView1 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { UpdateThirdColumCell(e); } //CellContentDoubleClick event handler for your dataGridView1 private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { UpdateThirdColumCell(e); } private void UpdateThirdColumCell(DataGridViewCellEventArgs e) { if (e.ColumnIndex == 1)//The column index of the CheckBox column { DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex]; cell.Value = cell.EditingCellFormattedValue; dataGridView1.Invalidate(); if ((bool)cell.Value) { dataGridView1.CurrentCell = dataGridView1[e.ColumnIndex + 1, e.RowIndex]; } } } //CellStateChanged event handler for your dataGridView1 private void dataGridView1_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e) { if (e.Cell.ColumnIndex == 2 &amp;&amp; e.Cell.Selected) { dataGridView1.BeginEdit(false); } } </code></pre> <p>And that's all :)</p> <p><img src="https://i.stack.imgur.com/UZWWY.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload