vb2010 combobox automatic change text from items - vb.net

I am using vb2010 and I have a problem with combobox. My code below get the items from mysql database then add it to the combobox. When there is an item in combobox say for example "NERISON" when I input "N" in the combox and press tab, the combobox will automatically change the text to "NERISON" -what I don't want. I just want to leave it with "N" as text. How would I do that?
If Not e.KeyChar = ChrW(8) Then
txtprice.Text = ""
With cmb_particular
.Items.Clear()
load_dbase() ' connects to database
CNN.Open()
runSql("select particular from particular where status=0 and particular like '%" & .Text & "%' order by particular") ' my function for queries
While dr.Read
.Items.Add(dr("particular"))
End While
CNN.Close()
.SelectionStart = cmb_particular.Text.Length
.DroppedDown = True
End With
End If

Could it be that autofill / autocompelte is enabled in the combobox?
For WPF, set the following:
IsTextSearchEnabled = False
For Forms:
ComboBox.AutoCompleteMode = False

In your combobox properties be sure that AutoCompleteMode=None
#Nerison:
I 've added a comboBox in a form. I don't change anything. I check its properties:
ComboBox1.AutoCompleteMode=None
ComboBox1.AutoCompleteSource=None
ComboBox1.DropDownStyle=DropDown
I add a datatable as datasource. Now I have the bahaviour that you want. I type "N" and it doesn't suggest or append anything.
Could you please check it again?

Related

Pop up window with textbox after selecting checkbox

all
I am working on a project with vb.net and MySQL database.
Now for taking information I have added few checkboxes, and in case if user selects a checkbox named other I want a window to appear and it should have a text box and when user enters the text at that box, the details should be stored in db.
As you haven't provided much information I may can't answer exactly your question but check if this can help.
First Add LINQ to SQL (.dbml File) - Let's name it as XYZ and Dataset (.xsd File) - let's name this as XYZ too, to your project and then drag and drop your database table in both the files and save all.
Now going into your form which contains the check box you mentioned.
Add this code to you checkbox click_event.
If checkbox1.checked = True Then
Dim insertValue As String = ""
insertValue = InputBox("Enter text to insert", YourTitle, "")
If inserValue <> "" Then
Dim db as New XYZDataContext
Dim NewRec As New YourTableName With {.ColumnName = insertValue}
db.YourTableName.InsertOnSubmit(NewRec)
db.SubmitChanges()
Msgbox("Value added!")
End If
checkbox1.checked = False
End If
create your window in the designer and give it a name like someWindow. then in your code open the window from the click event of your checkbox. when you close the window don't dispose it. just hide it me.hide so when you window closes you can retrieve the data from your textbox.
Sub Test ()
Dim wd_SomeInfo as new someWindow
wd_SomeInfo.showdialog()
Dim result As String = wd_SomeInfo.txt_sometextbox.text
If result = "" Then cancel....
End Sub

Access Cascading Combobox clearing after change

I have some code to create a cascading Combobox in Access, which works correctly; the combobox filters to the list that I need. However, when I change the combobox it clears automatically, so I cannot use it.
Private Sub cobVehType_Change()
If CycleType(DLookup("VehicleType", "tblVehicleType", "VehicleTypeID =" & Me.cobVehType)) = "Miles" Then
Me.cobMainType.RowSource = "SELECT tblMainType.MainCycle FROM tblMainType WHERE (tblMainType.MainType)='Miles' And (tblMainType.SimilarTo)=False"
Else
Me.cobMainType.RowSource = "SELECT tblMainType.MainCycle FROM tblMainType WHERE (tblMainType.MainType)='Hours' And (tblMainType.SimilarTo)=False"
End If
End Sub
What else should I check?
You mean the combobox list does not have any items? Try refreshing the combobox:
Me.cobMainType.Requery
Should not need the DLookup as cobVehType should have all the info needed to provide the vehicle type.

Getting .value property when using a string and variable

I am creating a form in Access which will be used as an order sheet for classroom materials. I have the available resources listed and a text box next to the resource where the user inputs the quantity they desire.
My VBA code checks to see if any entries have been made by using the following. (I am using Nz() to allow for Null results):
QuantCheck = Nz(Box1.Value, 0) + Nz(Box2.Value, 0) + Nz(Box3.Value, 0)
Where "QuantCheck" is the variable I am using in the IF statement which begins the workflow:
If QuantCheck > 0 Then
I would like to clean this up by using some kind of loop statement, however I am not able to extract the .value from a string. I would love something like the following which I could incorporate into a loop:
"Box"&VariableNumber.Value
From what I can tell, I am not able to use a string (concatenated or otherwise) as the base for the .value call.
It is interesting that there is a way to accomplish this when using a SQL statement. I have this elsewhere in the code which works nicely:
SQLStr = "INSERT INTO OrderRequests VALUES (cbSchool, txtName, Title" & x & ".caption, Box" & x & ")"
Here I have a variable "x" which increases with each loop to change the Title line, and the Box line.
Any help is appreciated.
I suggest you use the Tag property of the controls. Put "QuantCheck" in the Tag property of any control you want to include. Then
Function QuantitiesExist(frm As Form) As Boolean
Dim Ctrl As Control
Const sQUANTCHK As String = "QuantCheck"
For Each Ctrl In frm.Controls
If Ctrl.Tag = sQUANTCHK Then
If Nz(Ctrl.Value) > 0 Then
QuantitiesExist = True
Exit For
End If
End If
Next Ctrl
End Function
Now you get self documenting code
If QuantitiesExist(Me) Then
And when you add/delete/change controls, you don't have to edit your code. Just set up new controls with the proper tags.
You could loop through the control on the for checking the names and then if it is the one you wanted take an action on it, is this what you was thinking of?
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If Ctrl.Name = "TxtPath" Then ' "Box" & VariableNumber Then
MsgBox Ctrl.Value
End If
Next

Verify multiple comboboxes/textboxes have value

I have a winform that has about 6 comboboxes and 3 textboxes. I also have a button that takes the values of aforementioned controls and inserts them into SQL. Is there a better way, than a bunch of nested if/then statements, to verify that the controls all have values before inserting the data? This gets ugly very fast. I have tried googling this answer, but I get too many ASPx answers. I will entertain any ideas you may have. I am just trying to find a better way to do this. Thanks for any help.
I think its not too hard.
This code shows error message about the first empty textbox or combobox. But you can easily modify to show error message for all empty comboboxes and textboxes if required.
Private Function ValidateMyControls() As Boolean
Dim allComboBoxes() As ComboBox = {ComboBox1, ComboBox2, ComboBox3} ' add all your comboboxes here
Dim allTextBoxes() As TextBox = {TextBox1, TextBox2, TextBox3} ' add all your textboxes here
Dim emptyTB As TextBox = allTextBoxes.Where(Function(f) f.Text = "").FirstOrDefault
Dim emptyCB As ComboBox = allComboBoxes.Where(Function(f) f.SelectedIndex = -1).FirstOrDefault
If emptyTB IsNot Nothing Then
MessageBox.Show("Please fill value in " & emptyTB.Name)
Return False
ElseIf emptyCB IsNot Nothing Then
MessageBox.Show("Please select a value in dropdown " & emptyCB.Name)
Return False
Else
' All set to go!
Return True
End If
End Function

Control & Tag Properties

I am trying to write a function called HasUnsavedChanges which basically should be called when you are closing the form. i.e after saving the item, it should check the values in the controls against the values in Tag property which are in the same function, e.g. txtFirstName.Tag = .ContactFirstname and txtFirstName.Text = .ContactFirstname. If there is any difference between the two, return True. On closing the form, if this function returns true, then ask if changes should be saved.
I think the right way would be to write a For loop to loop through the controls, but I'm stuck after that.
Assuming you have the .Text and .Tag properties stored in the same control, try something like this:
For Each objControl As Control In frmMain.Controls
If TypeOf objControl is TextBox Then
If objControl.Tag <> objControl.Text Then
'---Changes have been made!---
End if
End if
Next
Obviously, you'll need to replace "frmMain" with your form's name.