VB.NET Databound ComboBox need to force update in datasource when selection changes - vb.net

I have a combobox where the SelectedValue on the combo is bound to a property on a business object.
Everything works fine, but the property that's bound to the SelectedValue on the combo only gets updated when the focus leaves the control. I understand that the property doesn't get updated until the control is validated (loses focus), but I need it to update the datasource as soon as the dropdown is closed.
I know I could probably leave focus from the control on the DropDownClosed event but I'd prefer something a little less kludgy.
What's the best way to immediately update my datasource when the dropdown is closed?

Set the DataSourceUpdateMode to OnPropertyChanged. Here is similar problem:
[http://social.msdn.microsoft.com/Forums/en/winformsdatacontrols/thread/bc39342b-d9b5-4ad0-bd35-073869ccf8be][1]

The way I'd do it is to set (in the events) the OnUpdate of the combo box and put in the VB.net
Me.<business object>.Requery

Related

How to see if ComboBox is in DropDown State?

I have searched several forums but did not find answer for checking whether ComboBox is already DroppedDown via VBA code.
I have other code on Form_KeyDown events due to which anytime I press vbKeyDown it moves to next record. I need to check if ComboBox is DroppedDown then don't use other code and instead treat the default functionality of access where vbKeyDown will start scrolling through the items of ComboBox displayed in DropDown.
There is no such property, neither an event for OnDropDown or similar.
If the combobox has focus, you can force a dropdown using the DropDown method, but that's as close you can get.

Windows form freezes when bound combobox selection is made

I have a pretty simple form that brings up a certain record when the "caseNumber" is selected from the combobox. Although after a selection is made within the combobox, it will freeze the entire form on the record selected. I can't click on any other text boxes or buttons. I have to stop the debugger. No errors are thrown. I've read where this has happened to others, but no answers to the problem, that I can find.
There is no code behind it so far, as the form is bound to a dataset and should just bring up the rest of the information once the caseNumber is selected.
Changed the "Selected Value" dropbox to "none" on the data binding menu for the combobox.
Under DataBindings, go to Advanced and make sure DataSource update mode is on NOne
A lot of times this happens because there is a problem in the binding. Are you sure it's not binding the text value of the control(the combobobox) to the data?
The correct way to bind (under DataBindings, Advanced) was to bind it to the SelectedValue instead of Text.
Please let us know a little bit more how your combobox is binded.

vb.net Listview selectedItemChanged event fires when trying to select already selected item

Anyone has a clue what might go wrong? This behaviour happens after I make some changes in the grid that associates properties to the items in the listview, select a different item, at save prompt I cancel and revert the selection, now if I try to select the already selected item event fires. I dont know why.
I do change the selection programatically when I revert the selection if I cancel at the save promt.
I managed to reproduce this problem. It's resolved if you set the MultiSelect property to false. However, if you need multiple selections, another solution will be needed.
A UserControl 'wrapper' around the ListView that handles the SelectedItemChanged event and only responds if the item is different is an option.

DataGridView and checkboxes re-selecting automatically

I have a strange problem with a DataGridView I'm using which is bound to a table in VB.net
I've added a checkbox column to allow a user to tick a bunch of rows that I can then loop through and save off to a different table. All the checkboxes are enabled by default. So it's really a case of unchecking the rows which aren't required.
However, the DataGridView re-enables any checkbox that I click after I click on a checkbox in another row. So in effect, only one row can be unchecked at a time.
I'm sure I'm probably missing something obvious here?
EDIT: I forgot to mention this is a Windows form, not an ASP.net application.
I think this is what is happening. Please check if you have checked IsPostback while binding the datagridview. I think the click event of the checkbox is initiating a postback and it is rebinding itself.
HTH
I think the grid is refreshing and then redrawing the default values...
I got it working in the end, although I'm not sure exactly how. It must have been some property that I tweaked in the grid

VB.NET ComboBox Validating?

I have a ComboBox bound to a table field and I want to validate the selection, since only certain selections are valid depending on context. When in the On Validating Event how can I get the Value before or what it is in the table.field before selection changed?
The WinForms ComboBox control doesn't provide the functionality of being able to intercept a value change and cancel it. You can use the Validating event (or, as you describe, subclass the ComboBox and override OnValidating), but these only allow you to keep the focus on the control. You can't actually "cancel" a value change through the validating events.
There are several third-party (DevExpress, for example) packages that provide ComboBoxes that allow you to inspect both the initial and the new values when the value changes and cancel the change if desired, but the ComboBox provided in System.Windows.Forms does not.