monitor combobox for change vb.net - vb.net

How can I monitor a ComboBox for changes?
The SelectedIndexChanged event only firnges when selection is changed by choosing a different value from the combobox, I would like to monitor chaes when the selection is manually deleted and no value was chosen.
Thanks in advance!

Easy, simply use the event TextChanged:
Occurs when the Text property value changes.
See the MSDN Documentation about it.

Just extend combobox class and override SelectedIndexChange event to fit your needs.

You can select to Indexchange or Valuechange or Textchange
Then, you can try to put some code. Like record it for every change.
like adding below code to the Valuechange
listbox1.items.add = combobox1.selecteditem
Of course you must made the visible to false

Related

Setting focus to another control prevents current control value from changing in VB.NET

I have a ComboBox in a WinForms app written in VB.NET. In the .SelectionChangeCommitted event I want to change the focus to a different specific control to assist user workflow. However when I do that, the change is not saved on the initial ComboBox and the value & index are reverted to the original values.
I've used both myControl.Focus and myControl.Select
The Combobox is setup like this:
With ChoosePartType
.DisplayMember = "PartName"
.DataSource = GetTable(qry) 'This custom function returns a DataTable with fields PartNum and PartName
.ValueMember = "PartNum"
.SelectedIndex = -1
End With
I assume something in the changing focus is short-circuiting the property change. Is there a way to force that to happen before I change focus?
Note: seems like a different issue from WInforms Combobox SelectionChangeCommitted event doesn't always change SelectedValue
Similar to this but I don't use databindings: Combobox DataBinding Bug - Won't write value if programmatically losing focus
Try using:
ChoosePartType.SelectedItem.Row("PartNum")
Assuming that this is the first column of the control's datasource, this could be also written as:
ChoosePartType.SelectedItem.Row(0)

Word - how to uncheck checkboxes?

I have 4 checkboxes but we need to restrict selection to just a single one, meaning if you check the first, the other 3 will go unchecked. I know we could use ActiveX radio buttons but we'd prefer to avoid ActiveX if possible, plus with check boxes we have more control over the layout.
I've set the name of the checkbox appropriately to Check1:
And then I've put this very basic script into the Visual Basic section:
Private Sub Check1_Click()
Check1.Enabled = True
Check2.Enabled = False
Check3.Enabled = False
Check4.Enabled = False
End Sub
But unfortunately checking the first box doesn't uncheck the next 3.
Any ideas please? Thank you!
If these are Content Controls, as you indicate, then they do not have a CLICK event. Nor can they be identified by VBA by their Title property. The code you show us is for ActiveX controls, which you say you don't want to use...
Working with content control events is not as simple and intuitive as with ActiveX controls. Similar to form fields, Content Controls only have "editing" events that trigger on the user entering and exiting the content control. These events are available in the ThisDocument module, in the Document category.
The same ContentControlOnExit event triggers for ALL content controls in the document, so you need a Select Case or If conditional to query the ContentControl argument in order to know which content control was exited.
In order to address the other checkboxes you need to use the Document.SelectContentControlsByTitle (or ...ByTag) method which returns an array of all content controls with that title (or tag).
If you really want to emulate a "click" event then you need to insert a Custom XML Part in the document with nodes linked to the content controls. When the user changes the state of the control the ContentControlBeforeStoreUpdate event will trigger, letting you take action.
The property you need is Value, not Enabled.
The purpose of property Enabled is to prevent a control from being changed by user.
Additionaly, you need to prevent it from the events cascade. It means that when you change programatically the value of Check2, this will trigger Private Sub Check2_Click() and so on.
In order to make it work you should change your code like that:
Private Sub Check1_Click()
If Check1.Value Then
Check1.Value = True
Check2.Value = False
Check3.Value = False
Check4.Value = False
End If
End Sub
and similarly for the other check boxes.
For your purpose radio buttons will be better choice. Radio buttons have built-in functionality to uncheck currently selected button if other one is checked.

Removing Item from Combobox without Firing Change Event

I am creating a userform in Word VBA that only has one combobox named cboType and one command button named cmdNext. In default, cboType have Null value and cmdNext is disabled.
I use cboType_Change event so that when an item is selected from the combobox, cmdNext is enabled and the combobox value is stored to a variable Type. However, I have another sub that will remove each item in cboType when cmdNext is clicked. I find out that removing item also fire the cboType_Change. I don't want this to happen because it will also change the value in variable Type.
In order to overcome this, I have tried using cboType_AfterUpdate event instead of cboType_Change, but I found out that this event will be fired only if the focus moved from cboType (cmiiw). Meanwhile, I don't have any other active/enabled control in the userform, so the cboType_AfterUpdate event won't be fired (the combobox value won't be stored to variable Type and cmdNext won't be enabled).
Any suggestion on how to do this?
If you just want the function to be called, can't you use
Call cboType_AfterUpdate()
to call this manually when the user clicks the cmdNext button?
Not sure if this solves your initial problem that cboType_Change is called when you change some value in the combobox.

Access form: trapping date changes in textbox

On a normal textbox, I usually use the AfterUpdate event to perform some action. That means the user has to press Enter or Tab after typing, or click in another control, and I have always been happy with that behaviour.
Now I am setting up a Date filter in the header of a continuous form in Access 2010, and I realize that changing the date through the little calendar that comes automatically, does NOT fire the AfterUpdate event, forcing to press Enter after selecting the correct date, which is a bit heavy.
Using OnChange would trigger at every character entered, which is not nice either.
Any suggestion ?
It is a bit late reply but I hope it will help the others.
When using textbox as a DatePicker you should use Change Event with your filter.
However when you are checking your textbox like Form_name.TextboxName it will show last picked date. To avoid that and use currently selected one you need to provide current date like Form_name.TextboxName.Text. Careful here because .Text property is sensitive to focus.
...in short:
Form_name.TextboxName - will show last picked date
Form_name.TextboxName.Text - will show currently picked date
well, after you select a date from the date-picker, the Change event occurs for the TextBox control. Then, call a sub or function or set focus to another control... to avoid event fires for each pressed key, put something like:
if Len(me.activecontrol) < 10 then exit sub
I hope this helps
I use LostFocus event in the textbox. It allows to use the calendar tool and alter the content. The User has to leave the textbox sooner or later, isn't it?
I use it in this way
Private Sub txt_FirstDate_Change()
txt_FirstDate = txt_FirstDate.Text
myfilter
End Sub

vb datagridview columntype change on edit

is there a method of setting up my datagridview to show me textboxcolumns until editmode is entered? At which time I will swap some textboxcolumns for bound comboboxcolumns. And at the end of validation/exit edit mode I can swap back?
If there's a method of doing this please share some links to examples.
I wouldn't try to switch DataGridView ColumnTypes like that. Sounds like a bad time.
Is your goal to have a DataGridViewComboBoxColumn that does not display the ComboBox dropdown button when it's not being edited? If so, there are two options:
Set the column's DataGridViewComboBoxColumn.DisplayStyleForCurrentCellOnly property to True.
Create your own DGV column based on the ComboBox by extending DataGridViewTextBoxCell. MSDN has a great article for doing this with the Calendar control here.
Of course you can. In the properties of the datagridview you can drill down to the column proprieties and switch the datatype to combo box. Very straight forward and easy.