我正在使用ERP系统,我需要一些帮助
我为Datagrid自动完成编写了代码。
此代码运行良好,但仅显示数据库中的一列记录。
我需要的是第一列能够像这样自动完成,并且还应该填充与第一列自动链接的相关列。
我该怎么做?
Dim 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