DatagridTemplateColumn.CellEdit selection changed - wpf

I have a ComboBox in a DataGridTemplateColumn.CellTemplate. When editing an existing entry the UpdateSourceTrigger=PropertyChanged fires on property change. However, I want it to fire on a new line as well just as if I have press (clicked) in any of the cell to start new entry.
By the way I am not using DataGridTemplateColumn.CellEditingTemplate for editing but DataGridTemplateColumn.CellTemplate which I thinks looks better unlike the default
In MS documentation it says DataGridCell.Selected Event Occurs when the cell is selected. That means when one presses a KeyDown or mouse click in the cell. I guess what I want is how to select a cell through a ComboxBox selection changed event. I want when I select a record in the combobox to begin the a new line just as if I have started typing soemthin in any of the DataGrid cells.

Related

DataGridView EditMode - Force Cell Editing - Not working just setting CurrentCell and Focus

In my (not binded) DataGridView some cells are editable, and some are not.
When I click on an editable cell the focus goes there and i can write anything.
Then, if i press the key TAB the focus goes to the next cell.
But if the entered value is not valid, i can check the value from the event Grid_CellValidating and cancel the change using e.Cancel = True . If I do so, the focus stays in the same cell waiting for a valid value, instead of changing the current cell.
Until here all works as expected.
What I need now is, from a new modal window where I can select a value, set this value to a cell of the grid in the parent form and close the modal window.
This works, but I don't want just set the value to the cell. I want also to set the cell in "editing mode". I mean by "editing mode" that state where the cell content is selected and if you try to change the value, the event Grid_CellValidating fires and if the value is not valid, the logic in the Grid_CellValidating event can check it to decide if it's valid or not...
I didn't succeed with that.
This is the code I'm trying to use to make it work.
myGrid.Rows(myGrid.Rows.Count - 1).Cells("EID").Value = 1
myGrid.Focus()
myGrid.CurrentCell = myGrid("EID", myGrid.Rows.Count - 1)
myGrid.BeginEdit(True)
But this definitely does not work.
In fact, the focus is not even on the Grid. I can see the value 1 in the cell but the focus is not there. For example, if I press the key TAB I can see that the focus is on another control, not in the Grid.
What I expect is: If the value 1 is not valid, the event CellValidating fires and do the work...
Do you know what should I do to get the behavior I need?

How to remove focus from the Infragistics ultragrid cell when clicking outside?

I have an infragistics ultragrid control in a windows form. There is an 'Add New' button outside to insert new rows to the grid.
The problem I faced is, when I click the button outside the grid, while I'm editing a cell inside the grid, the cell doesn't lose focus. Because of this the edited new value is not updated to its underlying data source.
I need this cell to lose focus and update it's underlying data source, because the 'Add New' button creates a new row with this particular column having a default value which is calculated based on the previous row's edited value.
So any ideas on how to unfocus the ultragrid cell? This situation may apply to normal GridView also.
If your button is on a Toolbar, then the behavior you are seeing is expected because toolbars don't take focus. If this is the case before performing your logic you can use the PerformAction method of the grid and pass in UltraGridAction.CommitRow to force the row that was being editor to commit its updates.
For example:
this.ultraGrid1.PerformAction(UltraGridAction.CommitRow);
I used myUltraGrid.ActiveRow.Cells[0].Activate(); which also works. But the solution by #alhalama is better one I guess.

Not selecting item in combobox

I need the following behavior for WPF Combobox:
i need autofilter in combobox. Took the implementation from here. But when there are several items in dropdown that are almost same-when i press DOWN it just selects the first one from list and hides others(see video of current behavior here: http://www.youtube.com/watch?v=_WYAgMTxc4M). If i want the second possible-i have to select it with mouse or write down the whole item display name in editable part of combobox. Is it possible to select item without changing editable part of the combobox, until i press ENTER, for example?
I think that problem is when you select the item, it fill the text area of ComboBox, than it notify that filter text changed and it applied new filter for the list, and the only one item remains in the list.
You should to rewrite this behavior that will apply filter only if KeyPressed / KeyDown / KeyUp events was fired.

Toggle Selected Row in WPF DataGrid

I want to be able to toggle selection when a row is clicked. So, first click should highlight it and second click (again on the row) should unhighlight it (and fire an event). Is it even possible? I'm using a OnSelectionChanged event but that gets fired only when I click on a different row than the selected one.
there a some useful answers here(searching the visual tree) or here(check in PreviewMouseLeftButtonDown).

Problem with combobox dropdown

I have a problem regarding combobox dropdown. Once a dropdown is opened, if I want to move focus to other control (say a textbox), I need to click twice because on first click, the combo dropdown is closed and then on second click, the textbox gets focus. How should I fix this? Please help.
You could listen to the DropDownList.SelectedIndexChanged event, and in the event handler set focus to the next control, either by setting TextBox.Focus(), or by calling System.Windows.Forms.Control.SelectNextControl()
I think this would be 'non standard' behaviour for what its worth. Its quite normal to expect the user to tab or select the next control after using a drop down.
Edit: Sorry, in a WPF ComboBox the equivalent event is SelectionChanged, but on reflection you'd be better using OnDropDownClosed. This would mean you only move the focus specifically after using the drop down rather than just whenever the value changes.

Resources