Selecting button in Winform ToolStrip - vb.net

Reference Image
I want to select a button("Exit") on the ToolStrip after pressing a button ("ButtonFocus To Exit") outside the toolstrip.
I used ExitToolStripButton.Select() on ButtonFocusToExit.Click but which seems like its selecting the button ("Exit") but when i pressed enter it never execute the code in "ExitToolStripButton_Click" .
So the button is still not active. Can anyone have fix to it?

Got the solution ...
First focus on the ToolStrip and then Select the Control on the Toolstrip
ToolStrip1.Focus()
ExitToolStripButton.Select()

Check if event is missing the event handler
Select the ExitToolStripButton > go to
properties > events tab> Click Event >
select the ExitToolStripButton_Click

You want to execute the ExitToolStripButton codebehind? You can call ExitToolStripButton.PerformClick();

Make sure it has focus. Are you sure the function you are using actually give the object focus? It could just give it the appearance of selection.
According to MSDN:
Select | Selects the item. (inherited from ToolStripItem)
It doesn't say anything about focusing it.

Related

How can I set my ComboBox to allow the user to type in the first few characters and then automatically select the item by pressing ENTER?

I have a feeling this is a very simple thing that I'm overlooking.
I have two ComboBoxes that allow users to search for/select the record that they want to view. One is filled with Customer Names and the other is filled with Customer Numbers, so the user can look for a particular record by either selecting the Name or Number.
Each ComboBox is filled by a Data Table returned from a SQL Server database.
Each ComboBox has DropDownStyle set to DropDown, AutoCompleteMode set to SuggestAppend and AutoCompleteSource set to ListItems.
The user can either select by clicking the DropDown arrow and then clicking on the item they was or they can begin by typing and the ComboBox narrows the number of items in the list based on the characters the user is typing.
Using the mouse to click on the item in the list that they want works fine...it fires off a routine to retrieve the selected item from the database.
However, when the user types in the desired selection and presses ENTER, nothing happens. They must click the DropDown arrow and click on the item in order for the program to pull the appropriate record.
How do I get the ComboBox to pull the appropriate record when the user hits enter?
I'm using Visual Basic.
From the sounds of it, you need three events.
You need to use a timer to know when the user has stopped typing. To do that, you need one event would be when that field they're typing in has it's value change (<control's name>.TextChanged). That would start/restart a timer ticking (so that the user has a couple seconds to pause before the next event fires).
The next event would be the Tick event for that timer. That event would stop the timer, and then give focus to the right field so that when the user hits ENTER, they're not hitting ENTER in the field they've been typing in. You'll need to write a function to look up the right item in the ComboBox and call that.
Then you'd have a third event, either KeyPress, KeyDown, or KeyUp on the ComboBox itself. I'd lean towards the KeyUp to avoid issues if the user holds ENTER for whatever reason. That'd be what selects the item.
As a final FYI, I'm assuming you're using Visual Studio to write your code. If not, you should, and if you are/once you are, you can select the field you want to work with in the drop-down at the top left of the editor and then look at the associated events in the top right drop-down.
Thank you to JMichael for getting me on the right track with this one. I'm posting my solution here just in case it helps someone who has a similar question in the future:
The code that I added to the ComboBox's SelectionChangeCommitted event needed also to be added to the ComboBox's KeyUp event:
Private Sub cboPolicySearch_KeyUp(sended as Object, e As KeyEventArgs) Handles cboPolicySearch.KeyUp
If e.KeyCode = Keys.Enter Then
GetSelectedPolicySearchRecord()
e.Handled = True
End If
End Sub 'cboPolicySearch_KeyUp
The GetSelectedPolicySearchRecord() sub contained all of the information I needed to call my SQL Stored Procedure to select the data for the record that the user selected in the ComboBox.
Previously, this was only being called from the ComboBox's "SelectionChangeCommitted" event which is executed when the user clicks the drop down and then clicks a policy number from the drop down list.
I needed to add the same call to the GetSelectedPolicySearchRecord in the ComboBox's "KeyUp" event for when the user presses enter.

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

Determine if an item is selected in a listview box

Using VB.net 2010 i am trying to figure out if an item was selected or not. Reason being is that if the user clicks on an item and pushes a button then everything works just fine. However, if the user selects an item and then clicks on a blank spot on the bottom of the listview and then clicks the button then it crashes.
My code is this:
If (lstMaster.SelectedItems(0).SubItems(1).Text) Is Nothing Then
MsgBox("test")
End If
Any help would be great! :o)
David
Ensure that something is selected first by checking that SelectedItems is not empty.
lstMaster.SelectedItems.Count > 0
check lstMaster.SelectedItems(0).Selected
Not sure if I've understood you correctly - Try using the ListView MouseMove event and check that lstMaster.SelectedItems.Count > 0 if you want to change the Enable property of a Button based on whether a row has been selected or not within your ListView control.
Use this checking with "If/EndIf" construction:
ListView1.Items(0).Selected = True

vb.net designing questions

i have created a dynamic table through vb.net, so htmltable, htmltablerow, htmltablecell.
I have added all style and properties in there. so eg.
dim td as htmltablecell
td.style.add("width","100px")
td.style.add("color","blue")
now what i want to do is add the tag to each row. this is because the first td of every row is a checkbox. and then textboxes follow. So when anyone clicks on the textbox, i want to checkbox to get checked.
Any idea how I can do this?
Your question is near incomprehensible, consider revising?
td.style.add("color","blue") now what i want to do is add the tag to each row
Since your table is dynamic, to add more styles and properties onto htmltablerow, you would do just as you did with your htmltablecells.
So when anyone clicks on the textbox, i want to checkbox to get checked. Any idea how I can do this?
You're looking for what is called the on_click event for the textbox. Programatically, when this event is triggered, you check your checkbox. Here's an example with a on_click in a textbox.

Select dropdownlist item after button click

I have an asp drowndownlist and I'd like to change its selection after a button click. I can't seem to find a way to do this, is there a way? (Its a reset button of sorts, and I would like the dropdownlist to return to the "default" value.)
DropDownList.SelectedIndex = -1
In the click event can you do:
DropDownList.SelectedItem = "whatever";
DropDownList.DataBind()
?
Use
dropdownlist.ClearSelection()