By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,663 Members | 762 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,663 IT Pros & Developers. It's quick & easy.

Autocompletion on A RichTextBox

P: 5
My code is working fine when I get the suggestions from the ListView when I click them. The problem is if I type "a" and want "and" as my suggestion from the ListView, it gives me an output like this: aand

How can I solve this error from this code here:



Expand|Select|Wrap|Line Numbers
  1.     Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles RichTextBox1.KeyDown
  2.  
  3.         If e.KeyCode = Keys.Tab And ListView1.Visible Then
  4.             RichTextBox1.SelectedText = Mid(ListView1.FocusedItem.Text, wordParts.Length + 1, ListView1.FocusedItem.ToString - wordParts.Length)
  5.             e.SuppressKeyPress = True
  6.             ListView1.Visible = False
  7.  
  8.         ElseIf e.KeyCode = Keys.Tab And Not ListView1.Visible Then
  9.             RichTextBox1.SelectedText = ""
  10.             e.SuppressKeyPress = True
  11.  
  12.         ElseIf e.KeyCode = Keys.Up And ListView1.Visible Then
  13.  
  14.             If ListView1.SelectedIndices.Count <> 0 Then
  15.  
  16.                 ListView1.GetItemAt(ListView1.SelectedIndices.Count - 1, True)
  17.             End If
  18.             e.SuppressKeyPress = True
  19.  
  20.         ElseIf e.KeyCode = Keys.Down And ListView1.Visible Then
  21.  
  22.             If ListView1.SelectedIndices.Count <> ListView1.Items.Count - 1 Then
  23.  
  24.                 ListView1.GetItemAt(ListView1.SelectedIndices.Count + 1, True)
  25.             End If
  26.             e.SuppressKeyPress = True
  27.  
  28.         ElseIf e.KeyCode = Keys.Left And ListView1.Visible Then
  29.             ListView1.Visible = False
  30.  
  31.         ElseIf e.KeyCode = Keys.Right And ListView1.Visible Then
  32.             ListView1.Visible = False
  33.  
  34.  
  35.         End If
  36.     End Sub
Nov 25 '15 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.