Make new row dirty programmatically and insert a new row after it in DataGridView

前端 未结 4 409
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 04:37

I\'ve an editable unbounded datagridview. I\'m changing the value of new row programmatically.

Normally, when user types in any field of a new row, it becomes dirty

相关标签:
4条回答
  • 2021-01-18 04:49

    I think (I'm not sure, though), that you're trying to insert a row after the New Row...which is not possible. Changing your code to this

    myGrid.Rows.Insert(e.RowIndex - 1, 1);
    

    Should insert the row before the New Row, which should work.

    0 讨论(0)
  • 2021-01-18 04:50

    Here I got the solution

    myGrid.NotifyCurrentCellDirty(true);
    
    0 讨论(0)
  • 2021-01-18 05:05

    I am working on winforms DataGridView. In my case i tried @iSid solution, but here is an aid in that, i tried this

    myGrid.NotifyCurrentCellDirty(true);
    myGrid.NotifyCurrentCellDirty(false);
    

    By only making current cell dirty in not working, you have to commit that cell also. In the next command i am flagging the current cell is not dirty, this will enforce datagridview to add a dirty row. It is working in my project.

    0 讨论(0)
  • 2021-01-18 05:09

    This is really really late considering the question timeframe, but the accepted answer did not work for me. What ended up resolving it for me was first inserting a row above the dirty row, then editing that 'clean' row instead.

    if (e.RowIndex == myGrid.Rows.Count - 1)
    {
        myGrid.Rows.Add();
    }
    myGrid[e.ColumnIndex, e.RowIndex].Value = etd.ResultText; // Edit at your leisure.
    
    0 讨论(0)
提交回复
热议问题