Apo*_*fix 3 .net c# gridview devexpress winforms
我正在使用 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;
}
}
Run Code Online (Sandbox Code Playgroud)
也许我必须先将它们附加到行中,但是如何呢?
DataSource尝试在保存之前将更改发布到底层:
if (gridView1.IsEditing)
gridView1.CloseEditor();
if (gridView1.FocusedRowModified)
gridView1.UpdateCurrentRow();
Run Code Online (Sandbox Code Playgroud)