Re: Can I implement an autofill feature with a textbox?

corbinamman_at_gmail.com
Date: 01/14/05


Date: 14 Jan 2005 12:57:29 -0800

Thanks to Warmrain for the help. I don't want the user to have to hit
the arrow keys, though. In my component, each time a character is
typed, the Text property is evaluated against an array of possible
values, and if one is found then the rest of the suggested text is
appended to the already-typed text and the appended part is highlighted
so that if the user hits yet another key the appended suggestion will
be overwritten and the process starts over. Here's my user control. I
left out the code that was automatically generated by VS.NET. There is
nothing in there special. I would like to make this work so that if
there are multiple matches, you can cycle through them with the arrow
keys. But I didn't have time to work on this feature. If anyone wants
to post an edited version of this class that would do that, I would
appreciate it.

Public Class AutofillTextbox

Inherits System.Windows.Forms.TextBox

Private mAutoFill As New ArrayList
Private mblnLockout As Boolean
Private mintLastKeystroke As Integer

Public Property AutoFillArray() As ArrayList
Get
AutoFillArray = mAutoFill
End Get
Set(ByVal Value As ArrayList)
mAutoFill = Value
'sort the items in order that the items are matched
alphabetically
If Not mAutoFill Is Nothing Then mAutoFill.Sort()
End Set
End Property

Private Sub AutofillTextbox_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.TextChanged

Dim iLen As Integer = Len(Me.Text)

Try

If mblnLockout = False And iLen > 0 And mintLastKeystroke
>= 30 And Not mAutoFill Is Nothing Then

'avoid callilng this method recursively by setting this
flag to true.
mblnLockout = True

'cycle through the ArrayList in search of an item that
matches the typed text.
Dim myEnumerator As System.Collections.IEnumerator =
mAutoFill.GetEnumerator()
While myEnumerator.MoveNext()
If
UCase(myEnumerator.Current).StartsWith(UCase(Me.Text)) And
Len(myEnumerator.Current) > iLen Then
'a match is found, and there is text in the
match that needs to be appended and highlighted.
Me.Text = myEnumerator.Current
Me.Select(iLen, Len(myEnumerator.Current) -
iLen)
Exit While
End If
End While

Else
'at least one of the following 4 conditions are true,
thus no action is called for.
'1. mblnLockout is true: skip code to avoid infinite
recursion.
'2. there is nothing in the textbox to match with
'3. the keystroke that fired this event was backspace
or some other non-character ascii code.
'4. the AutoFillArray property is not set: there is
nothing to match the typed text with.
End If

Catch ex As Exception
'ex handlers to be written later.
Finally
mblnLockout = False
End Try

End Sub

Private Sub AutofillTextbox_KeyPress(ByVal sender As Object, ByVal
e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
mintLastKeystroke = AscW(e.KeyChar)

    End Sub

End Class



Relevant Pages

  • Re: Firewall security: Re: Problems with simple Samba file share
    ... > against is people who already stole the private keys using them to do ... > once they had access to backups, but I grant you there are diffeernt ... Peter, do I really have to go back through nearly 200 posts and prove to ...
    (comp.os.linux.misc)
  • Re: Encrypting files in XP
    ... You need to get the other user's public key (_not_ private key!). ... All that user has to do is encrypt one file on his PC and he ... if you lose your private keys you lose access to your files for good! ... This password protect user profile in which private ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Certificates received from Windows CertStore: wrong public key (and incorrec
    ... I just did again a few tests with new generated certificates with larger ... RSAParameters exported from oRSA always have sizes corresponding ... The bogus private RSAParameters would be used, ... > size RSA keys also). ...
    (microsoft.public.dotnet.security)
  • Re: SPC and PVK creation
    ... cert public keys and associated private keys in CSP keycontainers ... and it will automatically find the associated private keycontainer. ... The same keycontainer can be used directly to SN code ... keycontainer into SPC and PVK files. ...
    (microsoft.public.dotnet.security)