📄 defaultvb.aspx.vb
字号:
Imports System
Imports System.IO
Imports Telerik.QuickStart
Imports Telerik.WebControls
Imports System.Data
Imports System.Data.OleDb
Namespace Telerik.ComboboxExamplesVB.AutoCompleteDictionary
'/ <summary>
'/ Summary description for _Default.
'/ </summary>
Public Class DefaultVB
Inherits XhtmlPage
Protected WithEvents RadComboBox1 As Telerik.WebControls.RadComboBox
Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
Protected Checkbox2 As System.Web.UI.WebControls.CheckBox
Private dictionaryWords As New DataTable()
Private Sub LoadData()
Dim tdfPath As String = Server.MapPath("~/Combobox/Data/en-US.tdf")
If Cache("dictionaryWords") Is Nothing Then
Dim words As New DataTable("words")
Dim column As DataColumn = words.Columns.Add("word")
Dim word As String = [String].Empty
Dim sr As StreamReader = File.OpenText(tdfPath)
word = sr.ReadLine()
While Not (word Is Nothing)
Dim realWord As String = word.Split(":"c)(0)
words.Rows.Add(New String() {realWord})
word = sr.ReadLine()
End While
sr.Close()
Cache("dictionaryWords") = words
End If
dictionaryWords = CType(Cache("dictionaryWords"), DataTable)
End Sub 'LoadData
Private Sub RadComboBox1_ItemsRequested(o As Object, e As Telerik.WebControls.RadComboBoxItemsRequestedEventArgs) Handles RadComboBox1.ItemsRequested
LoadData()
RadComboBox1.Items.Clear()
Dim [text] As String = e.Text
Try
Dim rows As DataRow() = dictionaryWords.Select(("word LIKE '" + [text] + "*'"))
Dim itemsPerRequest As Integer = 20
Dim itemOffset As Integer = e.NumberOfItems
Dim endOffset As Integer = itemOffset + itemsPerRequest
If endOffset > rows.Length Then
endOffset = rows.Length
End If
Dim i As Integer
For i = itemOffset To endOffset - 1
RadComboBox1.Items.Add(New RadComboBoxItem(rows(i)("word").ToString(), rows(i)("word").ToString()))
Next i
If rows.Length > 0 Then
e.Message = [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), rows.Length.ToString())
Else
e.Message = "No matches"
End If
Catch ex As Exception
e.Message = "No matches"
End Try
End Sub 'RadComboBox1_ItemsRequested
Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
LoadData()
End If
End Sub 'Page_Load
Protected Overrides Sub OnInit(e As EventArgs)
'
' CODEGEN: This call is required by the ASP.NET Web Form Designer.
'
InitializeComponent()
MyBase.OnInit(e)
End Sub 'OnInit
'/ Required method for Designer support - do not modify
'/ the contents of this method with the code editor.
'/ </summary>
Private Sub InitializeComponent()
End Sub 'InitializeComponent
Private Sub CheckBox1_CheckedChanged(sender As Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
RadComboBox1.Text = [String].Empty
RadComboBox1.MarkFirstMatch = CheckBox1.Checked
End Sub 'CheckBox1_CheckedChanged
End Class 'DefaultVB
End Namespace 'Telerik.ComboboxExamplesVB.AutoCompleteDictionary
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -