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

时间:2014-11-03 10:43:07

标签: c# .net winforms gridview devexpress

我正在使用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 个答案:

答案 0 :(得分:4)

尝试在保存之前将更改发布到基础DataSource

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

if (gridView1.FocusedRowModified)
    gridView1.UpdateCurrentRow();
相关问题