Springen naar inhoud


- - - - -

Van oude VB naar nieuwe VB(Autocomplete textbox)


  • Log in a.u.b. om te beantwoorden
Er zijn 1 reacties in dit onderwerp

#1 demodownload

demodownload

    Junior Developer

  • Leden
  • PipPip
  • 98 berichten
    Laatst bezocht 08 jun 2012 00:21

Geplaatst op 10 september 2010 - 05:59

Hallo,

Wat ik deze keer probeer is een zoekfunctie van klanten (bestaat al) maar nu als in een textbox de handeling textchanged gebeurt dat deze automatisch zoekt naar de eventuele klanten in de database, een autocomplete functie zeg maar. Deze code vond ik voor een combobox, makkelijk aanpasbaar dacht ik dan maar deze code staat in een oudere code van VB.net waar ik HELEMAAL niet in thuis ben.

is het mogelijk dit tot een "light" versie te gaan omzetten, als iemand daar de tijd voor heeft?

Alvast bedankt!

Visual Basic Code:
' This example shows how to implement an auto-fill combo box. You often faced
' it on some sophisticated web pages. As characters are typed, the program finds
' the closest matching item from the combobox list and automatically fills in the
' remaining characters. A similar approach using event "Change" can be used to
' work with a text box and list box control.
'
' Copyright © 2003 RustemSoft.com
' -----------------------------------------------------------

Public Class Form1
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Public Sub New()
		MyBase.New()

		'This call is required by the Windows Form Designer.
		InitializeComponent()

		'Add any initialization after the InitializeComponent() call

	End Sub

	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
		If disposing Then
			If Not (components Is Nothing) Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(disposing)
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	Friend WithEvents cmdClose As System.Windows.Forms.Button
	Friend WithEvents cboRightCombo As System.Windows.Forms.ComboBox
	Friend WithEvents Label1 As System.Windows.Forms.Label
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
		Me.cmdClose = New System.Windows.Forms.Button
		Me.cboRightCombo = New System.Windows.Forms.ComboBox
		Me.Label1 = New System.Windows.Forms.Label
		Me.SuspendLayout()
		'
		'cmdClose
		'
		Me.cmdClose.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.cmdClose.Location = New System.Drawing.Point(98, 109)
		Me.cmdClose.Name = "cmdClose"
		Me.cmdClose.Size = New System.Drawing.Size(104, 40)
		Me.cmdClose.TabIndex = 0
		Me.cmdClose.Text = "Close"
		'
		'cboRightCombo
		'
		Me.cboRightCombo.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.cboRightCombo.Location = New System.Drawing.Point(35, 58)
		Me.cboRightCombo.Name = "cboRightCombo"
		Me.cboRightCombo.Size = New System.Drawing.Size(222, 24)
		Me.cboRightCombo.TabIndex = 0
		'
		'Label1
		'
		Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Label1.Location = New System.Drawing.Point(52, 19)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(184, 24)
		Me.Label1.TabIndex = 2
		Me.Label1.Text = "Company Name:"
		Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		'
		'Form1
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(292, 187)
		Me.Controls.Add(Me.Label1)
		Me.Controls.Add(Me.cboRightCombo)
		Me.Controls.Add(Me.cmdClose)
		Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
		Me.Name = "Form1"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "RightCombo"
		Me.ResumeLayout(False)

	End Sub

#End Region

	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
		' Retrieve all the Company Names in the table
		Dim AppPath As String = Mid(Application.ExecutablePath, 1, Len(Application.ExecutablePath) - 14)
		Dim strConn As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source = " + AppPath + "Samples.mdb"
		Dim dbConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(strConn)
		dbConn.Open()
		Dim DSet As New DataSet, SQLStr As String
		Dim cmd As System.Data.OleDb.OleDbCommand
		Dim dbAdaptr As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
		Dim tRow As DataRow, tTbl As DataTable
		With dbAdaptr
			.TableMappings.Add("Table", "Companies")
			SQLStr = "Select [Company Name] from Companies"
			cmd = New System.Data.OleDb.OleDbCommand(SQLStr, dbConn)
			cmd.CommandType = CommandType.Text
			.SelectCommand = cmd
			.Fill(DSet)
			.Dispose()
		End With
		DSet.AcceptChanges()
		tTbl = DSet.Tables.Item(0)
		DSet.Dispose()
		dbConn.Close()

		' fill out array by Company Names for cboRightCombo combobox
		cboRightCombo.Text = ""
		cboRightCombo.Items.Clear()
		cboRightCombo.BeginUpdate()
		' Load the Company Names into the ComboBox Control
		For Each tRow In tTbl.Rows
			cboRightCombo.Items.Add(tRow("Company Name").ToString)
		Next
		cboRightCombo.EndUpdate()

	End Sub
	' Close application
	Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
		Me.Close()
	End Sub

	' Use event "Change" for alphabetical search an appropriate
	' value in combo box list and put it into combobox Text.
	Private Sub cboRightCombo_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboRightCombo.TextChanged
		Dim boxIndex As Integer, lExst As Boolean
		Dim box As ComboBox = sender
		Dim txt As String = box.Text
		Dim posCursor As Integer = box.Selectionstart

		' If Cursor does not stay on the beginning of text box.
		If posCursor <> 0 Then
			lExst = False
			' Go in cycle through the combo box list to find the appropriate entry in the list
			For boxIndex = 0 To box.Items.Count - 1
				If UCase(Mid(box.Items(boxIndex), 1, posCursor)) = _
				   UCase(Mid(txt, 1, posCursor)) Then
					box.Text = box.Items(boxIndex)
					box.Selectionstart = posCursor
					lExst = True
					Exit For
				End If
			Next
			' We didn't find appropriate entry and return previous value to text box
			If Not lExst Then
				box.Text = Mid(txt, 1, posCursor - 1) + Mid(txt, posCursor + 1)
				box.Selectionstart = posCursor - 1
			End If
		End If

	End Sub
End Class




#2 RedThread

RedThread

    Beheerder VBIB

  • Beheerder
  • 3592 berichten
    Laatst bezocht gisteren, 10:26
  • LocatieTongeren,Belgium.
Inzender

Geplaatst op 10 september 2010 - 08:12

Beste DemoDownload,

Ik heb dit bij "Project aanvraag" gezet aangezien je niet echt om ondersteuning vraagt; maar je iemand zoekt die je volledige code wilt porten naar een nieuwe vb.net versie.

mvg,
Mario




0 gebruiker(s) lezen dit onderwerp

0 lid(leden), 0 bezoeker(s), 0 anonieme gebruikers

Inloggen


Untitled 1

Met dank aan J├╝rgen voor de jarenlange inzet van visualbasic.be (anno dec 2000)
Met dank aan Mike en Ronneke voor de jarenlange inzet van vbib.be (anno dec 2010)
Met dank aan PascalBianca voor de jarenlange inzet van vbib.be (anno dec 2016)