DevExpress XtraGrid update on lost focus - c#

I want to disable the update event of the grid when the focus of the row is lost. So, after i added/edited a record and click on a previous record the grid should NOT update. Any ideas?

I believe, you want to make (all) grid rows unfocused and focus once the user clicks the grid. If yes, please refer:
Is it possible to set up the grid to have no focused row?

Related

Telerik RadGridView row in edit mode is not committed on lost focus

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.

How to get the clicked event of a wpf data grid?

I have a DataGrid with programmaticaly added rows (items) by adding an ItemSource.
I do not want the user to edit the cells so I set IsReadOnly = true;.
But I want them to click on cells and output which cell was clicked.
I was searching for a Clicked event and was surprised there is no such event for a DataGrid. I want a behaviour like buttons where it doesn't matter if it's clicked by the mouse, space bar, enter or whatever else the system accepts as a "Click".
So how can I achieve that?
Whatever is in the cell template (TextBlock, for instance) could be styled to handle the PreviewMouseUp event and pull the information you want from the control or bound object. The click event is specific to Button, TextBox and other controls that deal with mouse capture. Here is a link that discusses the dilemma you are facing: http://blog.scottlogic.com/2008/12/02/wpf-datagrid-detecting-clicked-cell-and-row.html. He provides examples on how to accomplish the task at hand.

gridView update after left row

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.

c# datagridview in tab control not drawing changes after first switch to tab

The setup:
I have a tab control and a datagridview (under the tabpageindex==2).
the datagridview is bound to a datatable.
In the tab control's tab_Selected event, if tabpageindex==2, I change some colors in some cells in the datagridview.
The problem:
The first time I select the tab with the datagridview in the application, the cells do not change color (i.e. the bound data is displayed, but my changing of colors does not work).
If I then click into another tab and back to this tab, then the colors appear.
Question:
Any idea why this is?
Should I be doing this differently, i.e. not in the tab_selected event?
(what I basically need is that certain cells have certain formats/colors depending on the data in the cells. I also e.g. call this drawing of cells function after the datagridview is sorted and there it works. just the first tab_selected event does not color...)
thanks for any help,
imran
Try doing the following:
After you update the cell, call InvalidateCell() on the DataGridView.
If that doesn't work, call Invalidate() on the DataGridView.
If that doesn't work, call Invalidate() on the TabControl.
It seems there is a bug with TabControl that when it has more than one tab, cellstyles that are created with code are only applied to the first tab's DataGridView, so you can move your DataGridView to the first tab or you can use the TabControl's SelectedIndexChanged event and put your styling code in this event .

WinForms C# DataGridView force refresh

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.

Categories