Hi all,
I am relatively new to .NET, C#, and DataGridView in particular. I am working on existing code, with a form that contains three controls, one of which is a DataGridView. If I am editing the data in a cell in the view, and then left click on parts of the other controls, the cell exits edit mode, as I would want it to, and when I choose to close the form I am correctly prompted as to whether or not I want to save the changes. The problem I have is that, when I am in edit mode in a grid cell, and then choose to close the form without clicking on any other control in the form, I am not queried for a save. The new value in the cell is never posted to the DataGridView control, and so the form knows nothing about needing to save the change, and the change is lost. Is there an event I should be setting on the form so that when I choose File/Close from the form's menu it will cause any cell that is open for edit to exit edit mode? I am not sure why it is working correctly when I click on another control, and not working as I would want it to when I choose File/Close.
One more question regarding this topic has to do with the fact that we are going to be moving to VS2008 (.NET 3.5) in a few months. I am wondering if this issue is appreciably more easily handled in that version, so that I may do well to just wait until we make the move. Either way, please send a 2005 answer if you would. This is a somewhat pressing issue.
Thanks in advance for your help...
Bruce
Loading
Bechir BejaouiPosted Oct 2, 2008, 4:37 PM
Make use of the lostFocus event of the data grid view as follow, populate the clicked button by this code
private void button1_Click(object sender, EventArgs e)
{
.....
dataGridView1.LostFocus+=new EventHandler(dataGridView1_LostFocus);
}
and or use the LostFocus event to automatically update the data base
private void dataGridView1_LostFocus(object sender, EventArgs e)
{
//TO DO: perform the code that update the database using the dataAdapter.Update(..) method
}
For the 2008 you can still relay on the .Net Framework 2.0 but what is new and very intersting is the LINQ with witch you can query an object collection
the WPF witch is a new kind of application neither Web nor windows, you will be surprised at first glance by some changements but take it easy for someone who is new in the .Net world first think to do is to master the .Net framework 2.0 contents witch is the heart of every think in dot net