none
how to DataGridView Autocomplete TextBox but get Autocomplete for TextBox from same columns ? RRS feed

  • Question

  • I use code (DataGridView Autocomplete TextBox) but this code get values Autocomplete TextBox from (Public Sub addItems) :

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            DataGridView1.ColumnCount = 3
            DataGridView1.Columns(0).Name = "Product ID"
            DataGridView1.Columns(1).Name = "Product Name"
            DataGridView1.Columns(2).Name = "Product Price"
    
            Dim row As String() = New String() {"1", "Product 1", "1000"}
            DataGridView1.Rows.Add(row)
            row = New String() {"2", "Product 2", "2000"}
            DataGridView1.Rows.Add(row)
            row = New String() {"3", "Product 3", "3000"}
            DataGridView1.Rows.Add(row)
            row = New String() {"4", "Product 4", "4000"}
            DataGridView1.Rows.Add(row)
    
        End Sub
        Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
            Dim titleText As String = DataGridView1.Columns(1).HeaderText
            If titleText.Equals("Product Name") Then
                Dim autoText As TextBox = TryCast(e.Control, TextBox)
                If autoText IsNot Nothing Then
                    autoText.AutoCompleteMode = AutoCompleteMode.Suggest
                    autoText.AutoCompleteSource = AutoCompleteSource.CustomSource
                    Dim DataCollection As New AutoCompleteStringCollection()
                    addItems(DataCollection)
                    autoText.AutoCompleteCustomSource = DataCollection
                End If
            End If
        End Sub
    
        Public Sub addItems(ByVal col As AutoCompleteStringCollection)
            col.Add("Product 1")
            col.Add("Product 2")
            col.Add("Product 3")
            col.Add("Product 4")
            col.Add("Product 5")
            col.Add("Product 6")
        End Sub
    I want get value (AutoComplete textbox) from same column (Product Name) automatically whitout need (Sub addItems)


    • Edited by srajmuneer Friday, October 20, 2017 2:57 PM
    Friday, October 20, 2017 2:04 PM

Answers

  • Hi srajmuneer,

    Based on your description, I'm not sure what do you want to do. Where do you want to get the data  to fill AutoCompleteStringCollection? SQL database or other?

    If you want to get some data from SQL database, here is the example that get some data from sql database to fill AutoCompleteStringCollection, please take a look:

    http://www.vb-tips.com/dbpages.aspx?ID=df40ced1-6b28-4538-b3e7-e3cd22d165ab

    Best Regards,

    Cherry

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. 
    Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by srajmuneer Monday, October 23, 2017 6:20 AM
    Monday, October 23, 2017 3:14 AM
    Moderator

All replies

  • Hello,

    First off don't call this your code when it came from here. With that said, what's wrong with obtaining values from another procedure?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, October 20, 2017 2:40 PM
    Moderator
  • Hello,

    First off don't call this your code when it came from here. With that said, what's wrong with obtaining values from another procedure?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    thanks Kareninstructor , I'm sorry for source code I have been wrong to express I edit my post , I want get value (AutoComplete textbox) from same column Because of the large number of data inputs in this column where it can not be predicted It means taking the value from the same column according to the previous input as in the Excel program

    Sunday, October 22, 2017 10:31 AM
  • Hi srajmuneer,

    Based on your description, I'm not sure what do you want to do. Where do you want to get the data  to fill AutoCompleteStringCollection? SQL database or other?

    If you want to get some data from SQL database, here is the example that get some data from sql database to fill AutoCompleteStringCollection, please take a look:

    http://www.vb-tips.com/dbpages.aspx?ID=df40ced1-6b28-4538-b3e7-e3cd22d165ab

    Best Regards,

    Cherry

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. 
    Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by srajmuneer Monday, October 23, 2017 6:20 AM
    Monday, October 23, 2017 3:14 AM
    Moderator
  • thank you Cherry Bu very much for help
    Monday, October 23, 2017 6:20 AM