有一gridview,及对应显示其值的一堆TextEdit
BO.xLookup activeRecord = null;
private void gridView__FocusedRowChanged(object sender, EventArgs e)
{
var z = dlg_Country.gridView_.GetFocusedRowCellValue("PK");
if (z==null||z.ToString()=="")
{
return;
}
activeRecord = _ss.Query<BO.xLookup>().FirstOrDefault(x => x.PK == (long)z);
foreach (var item in dlg_Country._BOFieldCollection)
{
item.controlBaseEdit.DataBindings.Clear();
item.controlBaseEdit.DataBindings.Add(new Binding("EditValue", activeRecord, item.fieldName));
}
}
gridview换行事件绑定item值
private void controlSimpleButton_ClickCancel(object sender, EventArgs e)
{
setUIBButton(UIBState.Canceling);
DisableEdit();
var z = dlg_Country.gridView_.GetFocusedRowCellValue("PK");
activeRecord = _ss.Query<TimeShare.BO.xLookup>().FirstOrDefault(x => x.PK == (long)z);
if (runNew == true)
{
runNew = false;
activeRecord = null;
}
else
{
activeRecord.Reload();
}
foreach (var item in dlg_Country._BOFieldCollection)
{
item.controlBaseEdit.DataBindings.Clear();
item.controlBaseEdit.DataBindings.Add(new Binding("EditValue", activeRecord, item.fieldName));
}
}
cancel时如果不是新建行那么activeRecord要Reload()
因为修改了TextEdit值时,即使不Save,内存中的值都已改变,就会显示值同Gridview对应不到。
也不是item同activeRecord 的绑定使item.editvalue值改变时,activeRecord对应值也发言为,只是
DB里的值没改变,需要使用Save() 才会保存到DB