Tuesday, September 27, 2011

AutoComplete ComboBox in VB.Net

http://www.codeproject.com/KB/cpp/autocomplete_combobox.aspx


Private Sub cboName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) 
                                                            Handles cboName.Leave
    Dim recRowView As DataRowView
    Dim recName As DB.tblNameRow

    AutoCompleteCombo_Leave(cboName)

    'OPTIONAL: Now you can  do some extra handling if you want


    'Get the Selected Record from my Data Bound Combo (Return Type is DataRowView)

    recRowView = cboName.SelectedItem
    If recRowView Is Nothing Then Exit Sub

    'Display the Name Info (Row Type comes from my bound Dataset)

    recName = recRowView.Row
    lblAccountNum.Text = recName.AccountNum
    lblCompanyName.Text = recName.CompanyName

End Sub

Private Sub cboName_KeyUp(ByVal sender As Object, 
              ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboName.KeyUp

    AutoCompleteCombo_KeyUp(cboName, e)

End Sub


Public Sub AutoCompleteCombo_KeyUp(ByVal cbo As ComboBox, ByVal e As KeyEventArgs)
    Dim sTypedText As String
    Dim iFoundIndex As Integer
    Dim oFoundItem As Object
    Dim sFoundText As String
    Dim sAppendText As String

    'Allow select keys without Autocompleting

    Select Case e.KeyCode
        Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete, Keys.Down
            Return
    End Select

    'Get the Typed Text and Find it in the list

    sTypedText = cbo.Text
    iFoundIndex = cbo.FindString(sTypedText)

    'If we found the Typed Text in the list then Autocomplete

    If iFoundIndex >= 0 Then

        'Get the Item from the list (Return Type depends if Datasource was bound 

        ' or List Created)

        oFoundItem = cbo.Items(iFoundIndex)

        'Use the ListControl.GetItemText to resolve the Name in case the Combo 

        ' was Data bound

        sFoundText = cbo.GetItemText(oFoundItem)

        'Append then found text to the typed text to preserve case

        sAppendText = sFoundText.Substring(sTypedText.Length)
        cbo.Text = sTypedText & sAppendText

        'Select the Appended Text

        cbo.SelectionStart = sTypedText.Length
        cbo.SelectionLength = sAppendText.Length

    End If

End Sub


Public Sub AutoCompleteCombo_Leave(ByVal cbo As ComboBox)
    Dim iFoundIndex As Integer

    iFoundIndex = cbo.FindStringExact(cbo.Text)

    cbo.SelectedIndex = iFoundIndex

End Sub


TEXTBOX AUTOCOMPLETE IN VB.NET.avi

http://youtu.be/YbzQbbQJQGg

DataTable.Select Method

[Visual Basic] 
Private Sub GetRowsByFilter()
    
    Dim customerTable As DataTable
    customerTable = new DataTable( "Customers" )

    ' Add columns
    customerTable.Columns.Add( "id", GetType(Integer) )
    customerTable.Columns.Add( "name", GetType(String) )

    ' Set PrimaryKey
    customerTable.Columns("id").Unique = true
    customerTable.PrimaryKey = new DataColumn() { customerTable.Columns("id") }

    ' add ten rows
    Dim id As Integer
    For id = 1 To 10
        customerTable.Rows.Add( _
            new object() { id, string.Format("customer{0}", id) } )
    Next id
    customerTable.AcceptChanges()

    ' add another ten rows
    For id = 11 To 20
        customerTable.Rows.Add( _
            new object() { id, string.Format("customer{0}", id) } )
    Next id

    Dim strExpr As String
    Dim strSort As String
    
    strExpr = "id > 5"
    ' Sort descending by CompanyName column.
    strSort = "name DESC"
    ' Use the Select method to find all rows matching the filter.
    Dim foundRows As DataRow() = _
        customerTable.Select( strExpr, strSort, DataViewRowState.Added )
    
    PrintRows( foundRows, "filtered rows")

    foundRows = customerTable.Select()
    PrintRows( foundRows, "all rows")
End Sub

Private Sub PrintRows( rows() As DataRow, label As String)
    Console.WriteLine( "\n{0}", label )
    If rows.Length <= 0 Then
        Console.WriteLine( "no rows found" )
        Exit Sub
    End If
    Dim r As DataRow
    Dim c As DataColumn
    For Each r In rows
        For Each c In r.Table.Columns
            Console.Write( "\t {0}", r(c) )
        Next c
        Console.WriteLine()
    Next r
End Sub

Visual Basic .NET Samples

http://www.xmlfox.com/VBsamples.htm#11

  • Convert Excel spreadsheet to PDF in .NET application
  • DataGridView Combo column (extended combobox)
  • DataGridView Numeric Column
  • .Net DataGrid combobox. Auto-fill and Dictionary.
  • Auto-fill combo box
  • .Net DataGrid Simple Sample.
  • Remove duplicates from an array
  • .Net XP DataGrid Button column Style.
  • .Net DataGrid Memo column Style.
  • .Net DataGrid DateTimePicker column Style.
  • How to Trap the Tab Key in a .NET Control?
  • How to format a datagrid column using a Date/Time format? How to update data in the column?
  • How to format a datagrid column using a Numeric format? How to update data in the column?
  • How to mask the data in a DataGrid Data column? How to mask the phone number (SSN, IP address) data?
  • How to draw a line in .NET? Line Control for .NET
  • autocomplete

    http://www.codeproject.com/KB/cpp/autocomplete_combobox.aspx

    combobox autocomplete - DROPDOWNLIST

    Bernie,

    To give me the idea, can you try if this is what you mean, you have to set
    the combobox to the normal dropdown however set that dropdownliststyle to
    true. I did not test it real deep, hower got the idea that it was working.

    \\\
    Private DropDownListStyle As Boolean
    Private Sub combobox1_KeyUp(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
            Dim cbo As ComboBox = DirectCast(sender, ComboBox)
            Select Case e.KeyCode
                Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete,
    Keys.Down
                    Return
            End Select
            Dim ComboBoxText As String = cbo.Text
            Dim FirstFound As Integer = cbo.FindString(ComboBoxText)
            If FirstFound >= 0 Then
                Dim FirstFoundItem As Object = cbo.Items(FirstFound)
                Dim FirstFoundText As String = cbo.GetItemText(FirstFoundItem)
                cbo.Text = FirstFoundText
                cbo.SelectionStart = ComboBoxText.Length
                cbo.SelectionLength = cbo.Text.Length
            Else
                If DropDownListStyle = True Then
                    cbo.Text = cbo.Text.Substring(0, cbo.Text.Length - 1)
                    cbo.SelectionStart = cbo.Text.Length
                End If
            End If
    End Sub
    ///

    Vb.net Tips and tricks

    http://www.bobpowell.net/

    Autocomplete text box in VB.net

    TextBox.AutoCompleteMode Property


    http://msdn.microsoft.com/en-us/library/chff42zw#Y0

    Friday, September 16, 2011

    Hp Printers