Hello every1 im new to this forum and this is my first time using the ultrgrid and im loving it,
the thing is i want the user to be able to insert using the ultra grid so i have a new button
and a save button, the ultragrid is bound to a datable btw
Here is the code of the new button:
private void NuevoB_Click(object sender, EventArgs e) { this.oDataTable.Rows.Add(); for (int i = 0; i < this.ultraGrid1.Rows.Count - 1; i++) this.ultraGrid1.Rows[i].Selected = false; ultraGrid1.Rows[this.ultraGrid1.Rows.Count - 1].Selected = true;
ultraGrid1.DisplayLayout.Override.AllowUpdate = DefaultableBoolean.True; for (int i = 0; i < this.ultraGrid1.Rows.Count -1; i++ ) this.ultraGrid1.Rows[i].Activation = Activation.NoEdit;
}
and my save button:
private void GrabarB_Click(object sender, EventArgs e) { insertaVP(); }
the function insertaVP() take the values of the new row that the user type and insert then on the data base
just fine except the value of the last columm where the user left the cursor at the moment he click
the save button, i notice that in order to save all the values the user got to click anywhere else in
the grid and then click the save button, that way it will save all of the values the user type.
Does anyone know how to solve this? i have tried setting the focus on other components before calling
the insertaVP() function but its still the same
thank you very much for you help this has solved my problem now its works just fine :)
Hi,
Sorry, I took a shortcut with the line of code. ExitEditMode in this case is an enum value. I assumed you were working in Visual Studio and so when you open the parens after PerformAction, the Intellisense will give you a list of the enum values.
Here's a more complete example:
this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode); this.ultraGrid1.UpdateData();
I'm not entirely sure if you even need the PerformAction method, actually. The UpdateData might exit edit mode for you implicitly. But it couldn't hurt to do it, just to be sure.
Luis_Z said:this code should go in my save button before calling my function right?
Yes. This code ensure that the grid has written any pending changes to it's DataSource. So you would call this code first before you attempt to update the back end from the data source.
Hi and thx for your answer, indeed my button is a binding navigator button, im trying your solution, like this ultragrid1.PerformAction(ExitEditMode) but its say that ExitEditMode is not a declared class , field etc, also this code should go in my save button before calling my function right?
The grid will commit any changes made by the user when the user leaves the cell or the grid loses focus by default. You can change this with the UpdateMode property.
My guess is that your Button is not actually a Button control, but is a toolbar button or something on a menu which does not take focus. Therefore the grid is not losing focus and the changes are not committed.
What you can do is calledgrid.PerformAction(ExitEditMode) to force the ActiveCell in the grid to leave edit mode and then call grid.UpdateData to commit any pending changes.