Do Access recordset fields() need initializing? - combobox

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

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?

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

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 List passing string

I have a VB6 application that has been running for quite sometime. Currently I'm trying to update one of the form that has a combobox 2.0. Because the combobox is populated with hundreds of items - I'm trying to update it so that users are able to click on a look up button next to it, where another window opens up with all the items from the combobox. User will be able to search by keyword and/or select an item and double click on it and have it appear in the combobox. The issue I'm having is with trying to pass no value or "" when CANCEL is clicked. I'm able to pass the value if I in the properties window my STYLE Is set to COMBO rather than list. However, the issue I come across is that with COMBO the value (text) in the combobox sometimes is not aligned properly. Is there a way to pass a "" value to a combobox 2.0 without changing the style to COMBO?
If they hit cancel set the ListIndex of your combo to -1 rather than setting the text property. This is the value for no item being selected.

Applying a DataGridViewComboBoxCell selection change immediately

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

Resources