Note that there are some explanatory texts on larger screens.

plurals
  1. PONew record not showing when using DataGridViewButtonColumn
    primarykey
    data
    text
    <p>I created a <code>DataGridView</code> that is bound to a <code>DataTable</code> as returned by Postgres:</p> <pre><code>dgOrderLines.DataSource = Program.DB.GetView(view); </code></pre> <p>I have implemented the <code>CellEndEdit</code> event:</p> <pre><code>dgOrderLines.CellEndEdit += new DataGridViewCellEventHandler(dgOrderLines_CellEndEdit); </code></pre> <p>Now, when I start editing a field, the grid automatically moves a "new record" into view that can be used if the edited record is saved:</p> <p><img src="https://i.stack.imgur.com/63D6g.png" alt="enter image description here"></p> <p>However, when I update the "new record" from <code>CellClick</code>, when the user clicks the <code>DataGridViewButtonColumn</code>, it is not added:</p> <p><img src="https://i.stack.imgur.com/AmNyf.png" alt="enter image description here"></p> <p>Adding by hand is not possible, because the <code>DataGrid</code> is bound.</p> <p>The code for editing the cell:</p> <pre><code> void dgOrderLines_CellEndEdit(object sender, DataGridViewCellEventArgs e) { // Get the edited cell DataGridViewCell cell = dgOrderLines.Rows[e.RowIndex].Cells[e.ColumnIndex]; string column_name = dgOrderLines.Columns[e.ColumnIndex].Name; if (cell.Value != null) { UpdateField(e.RowIndex, column_name, cell.Value.ToString()); } } </code></pre> <p>and, to update the row when using the button:</p> <pre><code> private void dgOrderLines_CellClick(object sender, DataGridViewCellEventArgs e) { if (dgOrderLines.Columns[e.ColumnIndex].CellType. Name.Equals("DataGridViewButtonCell")) { // art.SelectedArticles[0] holds the articleid for this record UpdateField(e.RowIndex, "articleid", "1234"); } } </code></pre>
    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.
 

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