Showing List of combobox while getting focus (vb.net) - vb.net

When we click on drop down combobox control in our windows form, it shows the list automatically.
But when we press tab and navigate to that control from keyboard it doesn't shows the list automatically. So in other to show the list automatically on receiving focus what should be done?

Set the DroppedDown property of the combobox equal to true.
Private Sub myComboBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles myComboBox.GotFocus
myComboBox.DroppedDown= true
End Sub

I would like to mention on thing here.
I used Enter event to show Drop down list with DroppedDown=true,
But When I type something in text area of combobox and if i leave the area to next control, entered text is lost.
My combobox is databound.

Related

Retrieving the item right-clicked in a listbox for a context menu action - vb.net

In my vb.net app, I've got a list box that contains a bunch of email addresses.
There's a context menu on the list box with view contact, modify and remove options.
I'm currently stuck on how to determine which item in listbox1.items the user has right-clicked for use in the context menu actions.... So say for example a user right clicks 'johnsmith#stackoverflow.com' and clicks remove I then need to say
listbox1.items.remove(THEITEMTHATWASRIGHTCLICKED)
But how would I determine THEITEMTHATWASRIGHTCLICKED?
I tried...
itemthatwasrightclicked = listbox1.SelectedIndex
But if I right click on an item before left-clicking, I get a returned index of -1. If I left click the item to select it first and then right click I get the correct index returned, so it seems that if a user right clicks without first left clicking, the item isn't selected as such.
I'm at a loss and any help is appreciated!
I feel like this should be something simple.
Thanks in advance! :)
The listbox class provides a method for this in the MSDN. You will want to use the IndexFromPoint(Point) method. When this method is called it returns the index for the item in the list box found at the coordinates of the Point specified. You will want to capture the coordinates of the right click event by implementing this within the MouseDown event of the ListBox.
In its most basic form, the code for this would be as follows.
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
If e.Button = MouseButtons.Right Then
ListBox1.SelectedIndex = ListBox1.IndexFromPoint(e.X, e.Y)
End If
End Sub

How to stop a user from pressing a button more than once

I've got a small problem of having a button and a combo box. In this situation the combobox holds values from 1 to 10. The enter button allows the user to select how many dynamic objects they want to produce however my program crashes every time I press enter after selecting another value and pressing enter again. So is there any form of validation I can have for my button to stop users from pressing enter twice.
Use a flag to supress user events.
Clear it again if need be at the appropriate time.
Private Enter_Locked As Boolean
Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
If Enter_Locked Then Exit Sub
Enter_Locked = True
'do as you will here
End Sub

Message pop up?

What is the way to implement/mimic the Windows message popup that a user gets when, for instance when you try to rename a folder on the desktop using invalid characters?
I want to use this method in lieu of a message box.
You can achieve this by using ErrorProvider. It is located in your toolbox. Just drag and drop it into your form. To use it, example code
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text.Trim().Length > 6 Then
ErrorProvider1.SetError(TextBox1, "Input is too long!")
End If
End Sub
Method 2 : Using ToolTip. This can be found in your toolbox as well. Just drop it into your form and in the properties window, you can set the "tip" for each controls in your form.
Here is how it will look like when your cursor is hovering the controls.
If you dislike the rectangle pop up, you can change it to a ballon pop up by isBallon = true.

Disable combo box list

I want to disable a combo box dropdown list from showing in VB.NET and then enable it. How can I do this? The default value of the cbo box should be enabled for typing.
Thanks
After Searching for same to disable combo box in vb .net cant find good answer which help...
so i tried some thing like this
1st thing to do while disabling
combobox1.enabled=false
combobox1.beginupdate
2nd thing to do while enabling
combobox1.enabled=true
combobox1.endupdate
its looks simple and i dont found any problem but i have doubt may it effect any excecution speen or other object
I want to disable a combo box dropdown list from showing in VB.NET and then enable it.
Ok, use the .Visible property....
The default value of the cbo box should be enabled for typing
Oh.... then.
The bad news.
You can't.
The good news.
You simply put a textbox on top of the combobox. When the dropdown should be disable, make the combobox invisible and show the textbox.
'Goodbye Combo
Private Sub HideComboButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HideComboButton.Click
comboBox.Visible = False
txtBox.Visible = True
End Sub
'Hello Combo
Private Sub ShowComboButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowComboButton.Click
comboBox.Visible = True
txtBox.Visible = False
End Sub
Try using the Enabled method eg comboBox1.Enabled = False Tellme how that works out for you
Try using dropdownstyle, simple can be used to remove list by manually closing the list in designer, then u can switch between dropdown and simple to achieve what you need.

how to add combobox items in listbox or listview

I want to know what control to be use on my project is it Listview or listbox???. I have a comboBox control on my project what I want to do is when I selected 1 item on my combobox it will automatically add on listbox or listview and when I selected more than 1 item I want to add it on listbox or listview on newline...
Is it simple, please help me to do that in listbox or listview..thanks!
Listbox > Is for viewing too but user can select it
Listview > Is for viewing only, user cannot select also it viewing by five view directly cause it's for viewing only
If your project wanted the list to be viewing from what have been select by Combobox, then you just pick List View, but if you want for viewing also user can select it, better use listbox, so it's up to you.
Also you can know how the Tools work by focus your mouse cursor to the tool, then it will pop up an tooltip that write what the tool for.
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ListView1.Items.Add(ComboBox1.SelectedIndex)
End Sub
That is the code to viewing in listview for what you select in combobox
For clearing all the item in the Listview or listbox, just write to your form_load
Listview.items.clear
Why i said in form load, cause the list just for viewing, of course every time the form begin to run, it will need blank list, so the best is put in form load
UPDATE
To remove the selected index in listbox
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
ListView Items can be selected a couple of ways In the Properties window for the ListBox the activation property allows an item to be activated by one click or two clicks. Here is an example of how the selected items can be used
If Me.ListView1.SelectedItems.Count = (1) Then
'Declare the selected item
Dim lviSelectedItem As ListViewItem = Me.listView1.SelectedItems(0)
'Now you can use it
lblLabel1.Text = lviSelecetedItem.Text
Else
lblLabel2.Text = "You can make Items selectable by switching CheckBoxes property to True in the Properties windows and using CheckBox event handlers"
End If