Reputation: 520
In my WinForm
application when I want to add a row in xtragrid
, I have a problem with getting the current value of the focused textbox
.
Assume I have a textBox
bind to Model.VchType.Title
, Before I click Save button my focus is on txtTitle
and I typed "title1" on it.
This is my code for Save button event:
Model.VchType row = xtraGrd.GetRow(xtraGrd.FocusedRowHandle) as Model.VchType;
I get null
for row.Title
after it hits the break point in this line of code.
And this problem only occurs when right before I click on save button focus is on txtTitle
.
-------- UPDATE ------------
Here is some of code of model:
[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;
}
}
}
Also I created columns by designer.
I fill a bindingSource
and set the property of the datasource
of grid to this bindingsource in designer.
And I don't think problem is column name , because if before I click save button I focus on another controller, It works fine and I get value for row.Title
.
Upvotes: 1
Views: 702
Reputation: 3979
You can focus another forms object before you save your data. So call:
anyControl.Select();
Before you save. This will close the open editor from your Textbox and post the changes to your DataSource. Normally this should be done by PostEditor();
which sometimes seems to lack.
Upvotes: 0
Reputation: 15797
You need to call
((GridView)xtraGrid.FocusedView).PostEditor();
or
gridView.PostEditor()
this will save the current value to the editor EditValue
.
Then you need to call view.UpdateCurrentRow()
to validate the focused row and save its values to the data source.
So you need something like this
((GridView)xtraGrid.FocusedView).PostEditor();
((GridView)xtraGrid.FocusedView).UpdateCurrentRow();
Model.VchType row = xtraGrd.GetRow(xtraGrd.FocusedRowHandle) as Model.VchType;
Upvotes: 1