I'm using Telerik's RadGridView in an MVVM app. In this particular gridview users can add rows and edit them. There's also a separate save button to save the items in the RadGridView.
The problem that I'm experiencing is that when the user inserts a new row, but doesn't press ENTER or ESC to cancel or commit, then clicks on the Save button, the bound collection is in a half-baked state. My preferred behavior would be for the gridview to commit the row edit whenever the user clicks anywhere outside of the row being edited. Is that possible?
Turns out it's a simple line of code that can solve this. I eventually was able to solve this myself by placing the following in the event that is triggered when clicking the save button:
gridview.CommitRowEdit(gridview.RowInEditMode);
It takes the current row that's being edited and commits it.
Related
I have a GridView, and buttons that do actions (Edit, Save, etc). The GridView is created dynamically. Once I press Edit button, I add textbox (controls) on every cell of the GridView, with their respective text value, so it can be edited.
The problem comes when I click Save button, because when the method starts, it seems like there isn't any textbox in the gridview... so that makes me think if it's because some autopostback stuff when the Save button it's clicked.
Any thoughts about solving that?
EDIT: Clarifying what I want:
1) I got a gridview with data,
2) I put the data of each cell from each row into textboxes,
3) I put those textboxes in the gridview,
4) I do change data in those textboxes,
5) I can't save that data because when I click the Save button, the data on the textboxes deletes itself
You can't avoid postbacks, ASP.NET works with them.
When you click the save button, the page does postback and the Load event fires. In that event, you have to rebuild the page as before you clicked Save (put the textboxes).
If you don't do it, the textboxes aren't there no more and no text can be saved.
Edit: gives unique names to your textboxes, it seems non-sense, but ASP.NET need to hooks on names
Is it possible to handle event left row on grid View? I would like to make update in database after left row in grid view. When user enter data in text box in grid view he has to click save button.
I use grid on web page and I use .net 2.0
If by left row event you mean unselecting then you can react on selectedindexchanged event and check if selected indedx is -1
I can think of two ways to do it. You could wire up an event on the tab key or blur event for the last control of the grid row. This means they've gotten to the last input, it does validation to make sure all the other required boxes are filled, and then it posts back the update, or you could add a focus event to controls in all rows in the gridview and keep track of which row they're on in that focus event. If the row changes you fire an update for the last row index.
My preference is the second option.
*Edit: You could save yourself some trouble and use event bubbling by wiring up the focus on the table or table body and let the controls' focus event bubble up.
I'm pretty new to c# and Winforms and I'm wondering what is the best approach to the following screen design.
I have a window that contain a Datagrid wich would be read-only. Beneath the grid, I have the detail of the records in differents fields (textbox, combobox, checkbox).
What I want is that when the user click on an item in the datagrid, the data will be shown in the detail fields.
That part is pretty easy, but I want to be able to update the fields automatically, wich means, I would prefer to not have to press a Save button.
Let's say that I click an item in the datagrid, change some value in the detail fields and the I click on another item in the datagrid, then I also want to perform some validation and calculation before the record get updated.
What I was thinking at first was to get the button for "new", "edit", "save" action and lock and unlock the fields accordingly and keep a flag to know if i need to insert or update the data, but then I realized that I would prefer to not have thoses button and have the save performed automatically.
Is there any sample somewhere that does what I want?
Also, would you guys using the built-in databinding functunality or just use a dataset object in code?
Pretty common scenario.
On selected row change of grid you know which datarow you shoul bind to the other controls. when same event happens again you validate and save or cancel in case of errors.
You can make use of DataGridView.CellEndEdit Event to get the new value and DataGridView.CellBeginEdit event to get the old value and update your data if there is any change
In a list view in C# how can I make all the fields in a column editable at once? Right now I have the standard edit button which allows me to update just one line at a time. I want the end user to be able to click a button and allow then to edit the column in its entirety.
Rebind the ListView with all TextBoxes when the user clicks edit.
You would have to manually track if you're in edit mode or not and on postback loop through all the rows retrieving the values from the textboxes and store them.
There is no built-in functionallity for what you're trying to do but it's possible.
Baby steps rolling... I have a form with a data grid bound to a table. I have some textboxes on the form bound to the table[columns], so as I scroll the grid, the textboxes show corresponding data.
I go to an "Edit Mode" of the textboxes and change the content and hit a save button. The grid doesn't refresh the changed context until I physically click in the cell which forces a call to the tables OnChanging and OnChanged events...
How can I FORCE whatever event to "flush" the table at the end of my edit and have it refreshed in the datagridview.
Thanks
Have you tried calling the dataGridView's Invalidate method?
this.dataGridView1.Invalidate();
Are you using a BindingSource? If so, call its EndEdit method on the TextBox's Leave event.