1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Private Sub GereCpVille(ByVal txtCP As TextBox, ByVal txtVille As TextBox)
If txtCP.Text.Replace(" ", "").Length = 3 AndAlso IsNumeric(txtCP.Text.Replace(" ", "")) Then
Dim oReader As SqlClient.SqlDataReader
Dim StrList As New AutoCompleteStringCollection
Dim SelStart As Integer
oReader = KappaDev.SQL.Data.getDataReaderExec("SELECT CP, VILLE FROM KD_Ville WHERE CP LIKE '" & txtCP.Text.Replace("'", "''") & "%' ORDER BY VILLE")
While oReader.Read
StrList.Add(oReader("CP") & " " & oReader("Ville"))
End While
oReader.Close()
oReader = Nothing
If StrList.Count > 0 Then
SelStart = txtCP.SelectionStart
GereCpTaille(txtCP, txtVille, True)
txtCP.AutoCompleteCustomSource = StrList
txtCP.AutoCompleteSource = AutoCompleteSource.CustomSource
txtCP.AutoCompleteMode = AutoCompleteMode.Suggest
txtCP.SelectionStart = SelStart
End If
ElseIf txtCP.Text.Length > 5 Then
txtVille.Text = txtCP.Text.Substring(6)
txtCP.Text = txtCP.Text.Substring(0, 5)
GereCpTaille(txtCP, txtVille, False)
End If
End Sub
' Fonction qui permet de redimensionner la taille du TextBox CodePostal
Private Sub GereCpTaille(ByVal txtCP As TextBox, ByVal txtVille As TextBox, Optional ByVal Agrandit As Boolean = False)
If Agrandit Then
If (txtCP.Left + txtCP.Width) < (txtVille.Left + txtVille.Width) Then
txtCP.Width = txtCP.Width + txtVille.Width + 6
End If
Else
If Not (txtCP.Left + txtCP.Width) < (txtVille.Left + txtVille.Width) Then
txtCP.Width = txtVille.Left - txtCP.Left - 6
End If
End If
End Sub |