Hi Peter,
Thanks for your post!
I assume you want to end the current editing mode and push the modifying
data into the datasource without changing the current cell and changing
the
focus to other controls. If I misunderstand you, please feel free to tell
me, thanks.
First, based on my test, Ian Semmel's suggestion of changing the current
cell programmatically will push the current modifying data into the
datasource without any problem.
//I use a timer to end the current edit
//for simplicity, I did not take last row into account.
private void timer1_Tick(object sender, System.EventArgs e)
{
DataGridCell dgc=this.dataGrid1.CurrentCell;
this.dataGrid1.CurrentCell=new DataGridCell(dgc.RowNumber+1,
dgc.ColumnNumber);
}
This works well on my test project. Do you have any problem get this
working?
Second, if you are creating the column styles yourself without using the
auto generated column styles in DataGrid, you can use dataGrid.EndEdit
method to get what you want, like this:
private void timer1_Tick(object sender, System.EventArgs e)
{
this.dataGrid1.EndEdit(this.dataGridTextBoxColumn1,
this.dataGrid1.CurrentCell.RowNumber, false);
this.dataGrid1.EndEdit(this.dataGridTextBoxColumn2,
this.dataGrid1.CurrentCell.RowNumber, false);
}
I have attached my sample project in this reply for your reference. This
sample project end the editing in 5 seconds, and it will display the
"column2"'s first cell value, so you may modify this cell value in
DataGrid
and wait for the display at runtime.(Note: run it in debug mode and see
the
Console.WriteLine output in "Output" window in VS.net2003 IDE)
Finally, can you tell me where you want to place the code to end the edit
mode? If you want to end the edit from another non-UI thread, the code
needs to be marshaled with Control.Invoke/BeginInvoke method calling,
because the .Net Winform uses STA threading model, which means any
manipulation to the GUI thread needs to be marshaled.
Hope this helps!
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.