Problem on Combobox textchange event VB.NET

J

jackson drex

Dear all,

I'm new to this VB.NET,my platform using now to do the development is Visual Studio 2008 using the VB.NET 2008 Window Form to create a lorry transportation management system.

I'm facing problem with the combobox textchange event now. I'm using MySQL 5.0 with SQLYog v5.29 to develop this system.

The following is a form code for the user to insert the Delivery Order document:
<pre>
Imports MySql.Data.MySqlClient

Public Class InputDO
Public Shared MyConnString As String = "Server=;Database=logistic_sysdb;Uid=root;Pwd=;"
Public Shared ObjMyConn As New MySqlConnection
Public Shared ObjComm As New MySqlCommand
Public Shared ObjRead As MySqlDataReader
Public Shared SQL As String

Dim ObjAdapter As MySqlDataAdapter
Dim ds As DataSet
Dim dt As DataTable
Dim dt1 As DataTable

Private Sub InputDO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer

ObjMyConn = New MySqlConnection(MyConnString)

'Load the information into Lorry Number Combobox
Try
SQL = "SELECT * FROM lorry_detail"
ds = New DataSet
ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
ObjAdapter.Fill(ds, "Lorry_Number")
dt = ds.Tables("Lorry_Number")

For i = 0 To dt.Rows.Count - 1
ComboBox1.Items.Add(dt.Rows(i).Item(0))
Next

Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
End Try

Try
SQL = "SELECT * FROM company_detail"

ds = New DataSet
ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
ObjAdapter.Fill(ds, "Client_Company")
dt1 = ds.Tables("Client_Company")

Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")

End Try

End Sub

Private Sub ComboBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.TextChanged
Dim x As String ' x = The Client Company name that stored at dt1
Dim i As Integer

x = ComboBox2.Text

For i = 0 To dt1.Rows.Count - 1
If x = dt1.Rows(i).Item(1) Then
ComboBox2.Items.Add(dt1.Rows(i).Item(1))
End If

Next

End Sub
End Class</pre>

I would like to show the similar Client company dropdown at the combobox while the user is typing the name of the company. I have select all the client company into dt1 from the database,and now how could I check if the user is typing each character into combobox2 will display the similar company name on the combobox?

Beside that,should I used a textbox or combobox for this event is better or any other ideas?

Hope someone can give me some help on this.

Thank you all for reading.
Regards
Jack

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng
 
H

Harry

Dear all,

I'm new to this VB.NET,my platform using now to do the development is
Visual Studio 2008 using the VB.NET 2008 Window Form to create a lorry
transportation management system.

I'm facing problem with the combobox textchange event now. I'm using MySQL
5.0 with SQLYog v5.29 to develop this system.

The following is a form code for the user to insert the Delivery Order
document:
<pre>
Imports MySql.Data.MySqlClient

Public Class InputDO
Public Shared MyConnString As String =
"Server=;Database=logistic_sysdb;Uid=root;Pwd=;"
Public Shared ObjMyConn As New MySqlConnection
Public Shared ObjComm As New MySqlCommand
Public Shared ObjRead As MySqlDataReader
Public Shared SQL As String

Dim ObjAdapter As MySqlDataAdapter
Dim ds As DataSet
Dim dt As DataTable
Dim dt1 As DataTable

Private Sub InputDO_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i As Integer

ObjMyConn = New MySqlConnection(MyConnString)

'Load the information into Lorry Number Combobox
Try
SQL = "SELECT * FROM lorry_detail"
ds = New DataSet
ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
ObjAdapter.Fill(ds, "Lorry_Number")
dt = ds.Tables("Lorry_Number")

For i = 0 To dt.Rows.Count - 1
ComboBox1.Items.Add(dt.Rows(i).Item(0))
Next

Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message,
MsgBoxStyle.OkOnly, "Connection Error !!")
End Try

Try
SQL = "SELECT * FROM company_detail"

ds = New DataSet
ObjAdapter = New MySqlDataAdapter(SQL, ObjMyConn)
ObjAdapter.Fill(ds, "Client_Company")
dt1 = ds.Tables("Client_Company")

Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message,
MsgBoxStyle.OkOnly, "Connection Error !!")

End Try

End Sub

Private Sub ComboBox2_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ComboBox2.TextChanged
Dim x As String ' x = The Client Company name that stored at dt1
Dim i As Integer

x = ComboBox2.Text

For i = 0 To dt1.Rows.Count - 1
If x = dt1.Rows(i).Item(1) Then
ComboBox2.Items.Add(dt1.Rows(i).Item(1))
End If

Next

End Sub
End Class</pre>

I would like to show the similar Client company dropdown at the combobox
while the user is typing the name of the company. I have select all the
client company into dt1 from the database,and now how could I check if the
user is typing each character into combobox2 will display the similar
company name on the combobox?

Beside that,should I used a textbox or combobox for this event is better
or any other ideas?

Hope someone can give me some help on this.

Thank you all for reading.
Regards
Jack

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng

In VB.Net, combo boxes are a whole new ball game. Once you get used to the
new paradigm, you will never want to go back to the old VB6 ones :)

To get started, populating as combo:

With MyCombo
..DataSource = oAccount.List_Company() 'this returns a datset of Companies
(you coulnd use a collection of Company objects)

..DisplayMember = "CompanyName" 'whatever field you want to display

..ValueMember = "CompanyrID" 'whatever is the key field

End With

Set AutoCompleteMode to SuggestAppend
Set AutoCompleteSource to ListItems

'-----------------------------------------------------------------------------------------------------------------------
Here is some nifty stuff you can do in the SelectedIndexChanged Event (an
example from my own code):

Private Sub Combo_SelectedIndexChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) _
Handles cboSettlement.SelectedIndexChanged, _
cboPromotion.SelectedIndexChanged

Select Case DirectCast(sender, ComboBox).Name

Case cboSettlement.Name

If (cboSettlement.SelectedIndex > -1) Then
btnLoad.Enabled = True
Dim pointer As Integer =
CInt(cboSettlement.SelectedValue.ToString)
oSettlement = New Settlement(DB, Glo.AppFolder, pointer)
End If

Case cboPromotion.Name

If (cboPromotion.SelectedIndex > -1) Then

Dim pointer As Integer =
CInt(cboPromotion.SelectedValue.ToString)

Dim invoice As List(Of dtoInvoice) =
Build_Invoice(oSettlement.List_PromotionDissection(pointer))

grdPromotion.SetDataBinding(invoice, EMPTY_STRING, True)

btnPromEmail.Enabled = (cboPromotion.Items.Count > ZERO)
AndAlso _
(DirectCast(cboPromotion.SelectedItem,
TRM8.WFL.SettlementPromotion).Promotion.Promoter.Email.Length > ZERO)
End If

End Select

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top