数据网格视图中的自动完成文本框列已停止工作



我有一个数据网格视图,其中一列是文本框。我编写了一个函数来填充数据库中的值并建议值以自动完成文本。我实现了它,然后我开始编码以使列自动增量 (Sr.No(,所以我又写了几行代码并更改了一些属性,突然文本框停止了自动完成。现在我尝试了所有可能的步骤来使其工作,但失败了。我不知道我更改的属性是什么影响了这个。 我把我的代码放在这里,请帮忙

这是用于编辑控件显示事件的代码...

Private Sub DataGridView2_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView2.EditingControlShowing

DataGridView2.BeginEdit(True)
Dim autoText As TextBox = TryCast(e.Control, TextBox)
If autoText IsNot Nothing Then
autoText.AutoCompleteMode = AutoCompleteMode.SuggestAppend
autoText.AutoCompleteCustomSource = AutoCompleteLoad()
autoText.AutoCompleteSource = AutoCompleteSource.CustomSource
End If
End Sub

这是我加载值的自动完成功能...

Public Function AutoCompleteLoad() As AutoCompleteStringCollection
Dim str As AutoCompleteStringCollection = New AutoCompleteStringCollection()
Dim ConnectionString As SqlConnection = New SqlConnection("data source=ADMIN-PCSQLEXPRESS; database=billdev;Trusted_Connection=yes;")
Dim strSQL As String = "SELECT * from bill;"
Dim SQLcommand As New SqlCommand(strSQL, ConnectionString)
ConnectionString.Open()
Dim reader As SqlDataReader
reader = SQLcommand.ExecuteReader()
While reader.Read()
str.Add(reader.Item(1))
End While
Return str
End Function

这是我在停止工作之前添加的额外代码,但我认为这没有任何区别

Private Sub DataGridView2_RowPrePaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView2.RowPrePaint
If e.RowIndex >= 0 Then
Me.DataGridView2.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
End If
End Sub

我找到了解决方案。 我尝试随机更改数据网格视图的每个属性。终于说到点子上了。 它是列本身的WRAP属性。

哇,我遇到了自动完成不起作用的问题,是的,自动换行阻止了自动完成的工作。谢谢Shreekant,对不起,你花了很长时间才发现,但它确实对我有帮助。

同样为了只对一列执行此操作,在 EditControlShow 过程中,我使用了:

如果the_DataGridView.Columns(the_DataGridView.CurrentCell.ColumnIndex(。标题文本 = "标题文本">

因此,它仅适用于该列。如此多的网页和YouTube视频检查列(1(,这纯粹是胡说八道。

最新更新