【发布时间】:2016-11-02 06:30:08
【问题描述】:
在我的WinForm 应用程序中,当我想在xtragrid 中添加一行时,我无法获取focused textbox 的当前值。
假设我有一个 textBox 绑定到 Model.VchType.Title ,在我点击保存按钮之前,我的 焦点 位于 txtTitle 上,我在上面输入了“title1”。
这是我保存按钮事件的代码:
Model.VchType row = xtraGrd.GetRow(xtraGrd.FocusedRowHandle) as Model.VchType;
row.Title 在到达这行代码的断点后,我得到了null。
只有在我点击保存按钮 focus 位于 txtTitle 之前,才会出现此问题。
-------- 更新 ------------
这是模型的一些代码:
[System.ComponentModel.DataAnnotations.Schema.Table("vwVchType", Schema = "Sle")]
[Serializable]
public class VchType : Entity
{
private int _ID;
[System.ComponentModel.DataAnnotations.Schema.Column]
[RnDisplayName(typeof(Rnw.Sle.Properties.Resources), "ID")]
public override int ID
{
get
{
return _ID;
}
set
{
_ID = value;
}
}
private string _Title;
[System.ComponentModel.DataAnnotations.Schema.Column]
[RnDisplayName(typeof(Rnw.Sle.Properties.Resources), "Title")]
public string Title
{
get
{
return _Title;
}
set
{
_Title = value;
}
}
}
我还创建了 designer 的专栏。
我填写了bindingSource 并将网格的datasource 的属性设置为设计器中的此绑定源。
而且我不认为问题出在列名上,因为如果在我点击保存按钮之前我将注意力集中在另一个控制器上,它可以正常工作并且我得到 row.Title 的价值。
【问题讨论】:
-
文本框是网格中的存储项吗?还是文本框脱离了 GridComponent?
-
@Sebi 它是网格中的存储库项
-
请在保存数据之前尝试将焦点设置在任何其他对象上。它不是那么干净,但我有一些项目对此很有帮助。因此,您保存方法中的第一个操作是将焦点设置为任何标签或某事。出格。
-
你试过this吗?
-
@Sebi 我试图将焦点放在另一个标签上,但没有成功
标签: c# winforms devexpress xtragrid