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

3

我正在使用EmbeddedNavigator的添加、编辑和删除按钮。我已经订阅了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;
            }
}

也许我需要先将它们附加到行中,但如何操作呢?
1个回答

5

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

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

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

1
谢谢!关闭编辑器就解决了问题。现在更改已经包含在内,我可以轻松地更新数据库中的行。 - Apostrofix
1
谢谢,我漏了updateCurrentRow方法的调用。 =D - RRoman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接