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

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.

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.

Silverlight 4: DataForm, currentItem and AutoCommit

I have a DataGrid and a DataForm. I'm assigning data to the DataForm with the currently selected Item in the datagrid individually as DataForm.CurrentItem. This means that I do not have any Next/Previous button on the DataForm and the user can switch to any row in the DataGrid.
My problem is that although I have set the property AutoCommit="True" on the DataForm, if the user edits something and clicks on another record in the DataGrid, it crashes.
How can I force it to save the DataForm when the user moves away from the form?
I got this working but I'm not sure whether this is correct. On SelectionChanged event of datagrid I added the following:
DataForm.CommitEdit();
and it stopped crashing and giving me the error. If anyone else has a better solution please do let me know.

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 Databound ComboBox need to force update in datasource when selection changes

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

Hiding columns in a datasheet

I am trying to hide specific columns in an Access 2007 split form through code. I need the form to check certain conditions to see whether it needs to display a column or not. I have code in the form's 'Activate' event to hide the column like this:
txtControl.ColumnHidden = True
This code works in the "Open" event, but if I hide the column on Activate, it won't display these changes until I close the form and open it again. I have tried calling the form's refresh, repaint, and requery methods, but this doesn't work. Please help!
Edit: Ideally, I need this event to occur whenever the focus switches to this form.That's why I'm using the Activate event rather than the Open event.
Try setting it in either the form's Current or Load events. You will also probably need to requery the control after setting that property: Me.TextControl.Requery Current is called every time a form's record is changed, the form is repainted or requeried. Load, as its name suggests, is called once, after the form has opened when the form loads its records. These have always been more reliable for me than using Activate, which really has to do with more the focus of the form, not really what you want.
I've had a problem like this before working in Access 2002. I was able to solve the problem with a subform by setting the subform source object equal to itself and then running the requery.
Me.SubForm.SourceObject = Me.SubForm.SourceObject
Me.SubForm.Requery
See if this technique works for your particular situation.