Applying a DataGridViewComboBoxCell selection change immediately - winforms

When I change a value in a DataGridViewComboBoxCell the new value is not immediately applied until that cell leaves focus.
Is there a way to have the new value applied immediately?

If you handle the EditingControlShowing event on the DataGridView, you can attach an event handler to the underlying ComboBox's SelectedIndexChanged event (or SelectedValueChanged, or any other ComboBox event). It will fire immediately whenever the ComboBox value changes, and you can do whatever you want with the new value.
There's example code for this in the MSDN docs for DataGridViewComboBoxEditingControl.

DataGridView.CommitEdit Method
This might be of some use to you as well. Handle the CurrentCellDirtyStateChanged event, check for Dirty, and Commit the edit. Then you can use the CurrentCell property to access the value that was selected (assuming it was validated).

DataGridView1.EndEdit()
Ignore this text, answer must be at least 30 characters

Related

Do Access recordset fields() need initializing?

I use the onClick event to get values from a combo box. As here:
Me.ComboSelProject.Recordset.Fields(0).Value
On the first onClick event, no matter what row has been selected, the value is from the first row of the recordset. On subsequent onClick events the value is for the selected row.
The value shown in the face of the combobox is always the correct selected value. IOW comboSelProject.text is always correct.
I've tried to initialize the combobox in the Form_load() procedure using:
Me.ComboSelClient.Value = Me.ComboSelClient.ItemData(0) but this has not helped.
Thanks for any help ...
The click event happens before the change event. If you want to use the new value, use the Change event.
And you should probably try to initialize the .text of the combo box rather than the .value

ByDeafult event for combobox value

I have some requirment which happen after the selecting from dropdown in combobox. But In some cases I getting default value. So for that which even i have to fier.
onchange and onselect is working when I select from the dropdown. But in my case I need event when Combo value is by default select.
So the change events don't fire when field's are created with a value so you will either have to run your post-change code after the init code (i.e. initComponent, constructor or render) or you could override the initValue method of the component and prevent it suspending those events on the initial value set.
Whether that's a good idea I'll leave up to you to decide!
Check out this Fiddle and the source file for the original code

WPF DataContext issue with datacontext object

I have created a simple sample with datacontext. Please get the sample from here : source I understand that the uses of DataContext is
If the user change any content in UI, it should be updated in the back end datacontext class without any additional work.
If we make any change in back end datacontext object, it should be updated in UI without any additional work.
In my sample,
If I click "click" button, the textbox value gets updated. - pass
If I click "update" button, the textbox value gets updated. - pass
If I click "clear" button, the textbox value not updated. - fail
After clicked "clear" button, If "click" or "update" button is clicked the textbox value not updated. - fail
Am I doing anything wrong? If yes, how can I initialize some value in the textbox in constructor, and after that if the user make changes, the datacontext object values need to be updated. If I update any value in code behind, the values need to updated in UI. Also if I click "clear" button all the textbox values need to be cleared. After that if user enter value again, the object need to update. How can I achieve it? Please help.
Note: In my sample I have commented some lines. In that i have casted the datacontext to the model class every time and changed it. Its working fine. Do i need to use that method to update values run time. Changing values in object will not update in UI?
The problem is that you consider the variable 'dc' linked to the DataContext, but that is not the case. To fix your code simply set the DataContext again after you change the 'dc' variable.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
dc = new Journal();
myPanel.DataContext = dc;
//myPanel.DataContext = new Journal();
}

Reset a ComboBox

I have a view that contains several ComboBox elements. For some reason old data remains from the previous time the view was opened and I would like to reset the combobox elements in the view every time it is opened. Is there a function that could that for me? I want it to be exactly how it is as if I rendered it the first time with the initial items. Would using setSelectedItem(vItem), setSelectedItemId(vItem), setSelectedKey(sKey), setShowSecondaryValues() help? If so, what do these keywords mean (selectedItem, selectedItemID, selectedKey, secondaryValues)?
Unfortunately you do not provide an example. Normally you bind your UI controls against a model, e.g. JSONModel. In this case the items of your ComboBox controls would be taken from the corresponding model. However, you can use method removeAllItems to achieve the desired behaviour.
UPDATE: Obviously the controls are bound and only the selection should be cleared.
Use setSelectedItem with value null to clear the selection. You could also use the binding to set the selected item automatically by using the selectedKey attribute, see example.

Combobox selectedindex changed event is getting invoked even when index is not changed

I have few items in combobox, i am selecting one item in that, selectindexchanged event is getting invoked. Then i am clicking on it and selecting the same item ( index is not getting changed) , but still selectedindexchanged event is getting invoked. Do we have any ways to avoid this? C# .Net ( WinForms)
Did you try debugging it to see where (if) the selected index has changed?
Else you can do a check in the event handler to see whether it's the same item selected or not, which you would do nothing if it is the same one.

Resources