none
Datagrid Autocomplete With Other Field

    Question

  • Hi All Brothers

    I am working on ERP system and i need one help

    I wrote code for Datagrid auto complete.

    this code is working perfect but it only showing one Column record from database

    what i need is

    i want first column is to autocomplete as i did and it should fill related columns automatically linked with first column.

    please guide me with Codes

    many Thanks

    My Code

    im strConn As String
        Dim da As SqlDataAdapter
        Dim conn As SqlConnection
        Dim ds As New DataSet
        strConn = ("Server= DESKTOP-QN6F623; Database = stock_in;Integrated Security = false;User ID=dis;Password=0m3rP@ss")
        conn = New SqlConnection(strConn)
        da = New SqlDataAdapter("Select * from [items]", conn)
        da.Fill(ds, "items")
        ItemsDataGridView.DataSource = ds.Tables("items")
        Dim cmd As New SqlCommand("Select item_number From items", conn)
        Dim dr As SqlDataReader
        conn.Open()
        dr = cmd.ExecuteReader
        Do While dr.Read
            scAutoComplete.Add(dr.GetString(0))
        Loop
        conn.Close()
    Private Sub ItemsDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles ItemsDataGridView.EditingControlShowing
    
        If ItemsDataGridView.CurrentCell.ColumnIndex = 1 AndAlso TypeOf e.Control Is TextBox Then
            With DirectCast(e.Control, TextBox)
                .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                .AutoCompleteSource = AutoCompleteSource.CustomSource
                .AutoCompleteCustomSource = scAutoComplete
            End With
        Else
            With DirectCast(e.Control, TextBox)
                .AutoCompleteMode = Nothing
                .AutoCompleteSource = AutoCompleteSource.CustomSource
                .AutoCompleteCustomSource = Nothing
            End With
        End If
    End Sub

    Wednesday, January 30, 2019 5:28 AM

Answers

  • Hi,

    Sorry, I can't understand what you mean.

    Best Regards,

    Alex


    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 Omi4u Friday, February 15, 2019 5:09 AM
    Monday, February 11, 2019 2:13 AM
    Moderator

All replies

  • Hi,

    I tried the code,it works well.

     Dim scAutoComplete2 As AutoCompleteStringCollection = New AutoCompleteStringCollection
     Dim cmd As New SqlCommand("Select Column1Name,Column2Name From items", conn)
                Dim dr As SqlDataReader
                dr = cmd.ExecuteReader
                Do While dr.Read
                    scAutoComplete.Add(dr.GetString(0))
                    scAutoComplete2.Add(dr.GetString(1))
                Loop
    
    
     If DataGridView1.CurrentCell.ColumnIndex = 0 AndAlso TypeOf e.Control Is TextBox Then
                With DirectCast(e.Control, TextBox)
                    .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                    .AutoCompleteSource = AutoCompleteSource.CustomSource
                    .AutoCompleteCustomSource = scAutoComplete
                End With
            End If
    
            If DataGridView1.CurrentCell.ColumnIndex = 1 AndAlso TypeOf e.Control Is TextBox Then
                With DirectCast(e.Control, TextBox)
                    .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                    .AutoCompleteSource = AutoCompleteSource.CustomSource
                    .AutoCompleteCustomSource = scAutoComplete2
                End With
            End If

    Best Regards,

    Alex


    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.

    Wednesday, January 30, 2019 6:54 AM
    Moderator
  • hi alex 

    thank you for your reply

    can you please write or refer me complete code using sql server. 

    i need to use it in stock in form and also with it i want something that i can use to update stock from stock in .....  i also need some idea of stock in process if you or anyone can help me ..

    thanks 

    Thursday, January 31, 2019 1:26 PM
  • Hi,

    Sorry, I can't understand what you mean.

    Best Regards,

    Alex


    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 Omi4u Friday, February 15, 2019 5:09 AM
    Monday, February 11, 2019 2:13 AM
    Moderator