DataGridView and checkboxes re-selecting automatically - vb.net

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

Related

in Access, Bound Combo Boxes do not update unless the form is already Dirty

I'm working on a fairly complex Access Database, trying to build forms with custom buttons for working with records. I'm using list boxes to display and navigate through records and all fields for existing records are disabled unless the user presses an edit button. The problem I'm having is that if I press the Edit or Add New button, enabling all of the fields, and then try to change the selection in a combo box, it does not update on the first try.
If I edit a text box first then the combo boxes work fine.
I've determined that the control's beforeUpdate and afterUpdate events are not firing on the first try but the action triggers the form_Dirty event and then it works as expected. I tried setting Me.Dirty = True with the Edit button and that solved the problem but it causes problems with some of my other code and it seems like an unnecessary workaround if only I understood the actual cause of the problem. It also works as expected if I leave the Combo Box unbound, but I am trying to build a template that doesn't require too much work to build new forms off of and I would rather not go that route.
It must have something to do with some bit of code I'm using because I can start a basic form and the combo boxes work fine.
I've started a basic test form and am adding code from my template form bit by bit until the problem arises, but it's a tedious process. Any help would be appreciated.
What am I missing? Is there some way of getting the Combo Box events to fire before the form is dirty?
UPDATE:
I have templates for a basic form, a form with a single subform, and a form with multiple subs in a tab control.
After some more testing I discovered that this problem does not apply to the basic form which has no subforms. This template uses similar code to the others for new, edit, cancel, save and delete buttons and for preventing accidental changes, preventing Form_unload during an edit and so on. The main difference I can think of off the top of my head is that the templates with subforms use class modules and collections to hold various data and pass it between the main form and subforms. Not sure if or how this might relate to combo box functionality.
I built most of this last winter then got too busy over the summer to work on it. Just now picking it up again and I'm having to re-learn a lot of the details of how my code works.
you can try to use Me.CboName.Requery in your After Update event.
I figured it out. I was calling a procedure with a form refresh in it from the Form_Dirty event and for whatever reason the refresh at exactly the wrong time was causing the combo box Before_Update and After_Update events to be skipped and the combo box value to not change. It was also causing text entered into a textbox to overwrite existing text on the first keystroke.

Opposite of SetFocus

MSAccess VBA:
Assume, in an arbitrary form, the focus is set to MyControl on that form.
How to "unset" the focus without giving the focus to another control?
I'm lokking for a code like
MyControl.UnsetFocus
In your circumstance, you probably want to just set focus back to the parent form. This meets the conditions of unsetting focus without giving another control focus, and tabbing or clicking will activate the focus / tab-navigation again from that form.
Here's an example:
Forms![MyForm].SetFocus
Note that per the documentation for SetFocus, if you attempt to SetFocus to a Form with child controls that have Enabled set, this will cause focus to automatically bounce to the first eligible child control per the documentation.
Form.SetFocus method (Access) # Microsoft Docs
The option to give focus to the parent form does work as proposed by meklarian
Alternatively, I recently had to do something similar but I wanted to update a textbox value and simply go back to whatever had focus before. This is another case where something like an "unsetfocus" would be awesome, but unfortunately doesn't exist.
Should you need to do something like this, the following works well
Screen.PreviousControl.SetFocus

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.

Is there an event which fires before a user enters a row into the datagridview in .net 3.5

I am trying to create a wrapper to replace the sheridan datagrid actvex control with a datagridview.
The sheridan datagrid control supports an event which fires just before the user is going to add a row to the grid called BeforeInsert.
Does anyone know of an equivalent event in the datagridview control or or some other code I could write which produces the same effect?
I'm having a look at all the events here, I don't see one for Adding or Inserting a row, just Added. Although there's one for Deleting and Deleted strangely enough. I won't pretend to know why. To your question, how exactly will users be adding rows? You could try playing around with the "AllowUserToAddRowsChanged" event and change that property programatically when the user wants to add a row.

ASP checkbox value incorrect when AutoPostBack is set to false

I am still relatively new at VB.Net and Visual Studio and I'm assuming that this is a simple fix, but I'm not sure.
I have an asp:checkbox control on an aspx page I am working on. This checkbox is within a custom control and previously was posting back every time it was clicked. I am in the process of ajaxifying the page and have come across a problem. When I remove the attribute AutoPostBack="True" from the asp:checkbox, the vb code returns False when I check myCheckbox.checked (this is on a postback else where on the page what has not be ajaxified), even though I can see the box is indeed checked.
I am assuming that because the checkbox no longer posts back, for some reason the VB code (or the view state maybe) doesn't see it as having been checked. Is this correct, and if so, how to I correct it?
I changed the checkbox from an ASP control to be an HTML input of type checkbox and now it works :)
I am assuming that because the checkbox no longer posts back, for some reason the VB code (or the view state maybe) doesn't see it as having been checked.
This is correct, your toggling of the checkbox is happening only on the client side, so your server side is unaware of the change.