How to save row changes in DevExpress GridView with the EmbeddedNavigator

天大地大妈咪最大 提交于 2019-12-11 03:58:26

问题


I am using the EmbeddedNavigator's Add, Edit and Remove buttons. I have subscribed to the gridControl1_EmbeddedNavigator_ButtonClick event and there I check which button is clicked.

The problem is that when I edit a cell and I press save changes(EndEdit) I don't see the new values. Here is the code that I have:

private void gridControl1_EmbeddedNavigator_ButtonClick(object sender, DevExpress.XtraEditors.NavigatorButtonClickEventArgs e)
{
    if (e.Button.ButtonType == DevExpress.XtraEditors.NavigatorButtonType.EndEdit)
            {
                if (MessageBox.Show("Do you want to save the changes?", "Save changes?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var rowHandle = gridView1.FocusedRowHandle;

                    // Here if the port is null by default, when I change it to 25
                    // I still get an empty string
                    var port = Convert.ToString(gridView1.GetRowCellValue(rowHandle, "ftpPort"));

                    var ftpConfig = new FtpConfiguration() { ftpPort = port };
                    // Update and save
                    context.UpdateFtpConfiguration(ftpConfig);
                    context.Save();
                }
                else
                    e.Handled = true;
            }
}

Maybe I have to append them to the row first, but how?


回答1:


Try to post your changes to underlying DataSource before saving it:

if (gridView1.IsEditing)
    gridView1.CloseEditor();

if (gridView1.FocusedRowModified)
    gridView1.UpdateCurrentRow();


来源:https://stackoverflow.com/questions/26712497/how-to-save-row-changes-in-devexpress-gridview-with-the-embeddednavigator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!