如何使用EmbeddedNavigator在DevExpress GridView中保存行更改

本文关键字:保存 GridView 何使用 EmbeddedNavigator DevExpress | 更新日期: 2023-09-27 18:29:01

我正在使用EmbeddedNavigator的"添加"、"编辑"answers"删除"按钮。我已经订阅了gridControl1_EmbeddedNavigator_ButtonClick事件,并在那里检查单击了哪个按钮。

问题是,当我编辑一个单元格并按下保存更改(EndEdit)时,我看不到新的值。这是我的代码:

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;
            }
}

也许我必须先把它们附加到行中,但怎么做呢?

如何使用EmbeddedNavigator在DevExpress GridView中保存行更改

在保存之前,尝试将您的更改发布到底层DataSource

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