开发者

how to put search functionality in dataGridView in vb.NET

开发者 https://www.devze.com 2023-04-07 16:24 出处:网络
How can I select a single cell fr开发者_JAVA百科om selected row in datagridView and after selecting that I want to put simple search functionality (like we have in our windows folders-typing any chara

How can I select a single cell fr开发者_JAVA百科om selected row in datagridView and after selecting that I want to put simple search functionality (like we have in our windows folders-typing any characters and search should work)?


I do not really understand your question. If you want to select one cell, you can use the celldoubleclick event for exemple. And the to get the selected cell, use e.rowindex and e.columnindex which will give you the row and the column where the cell is located.


You can try this as a possible solution.

Dim nwData as CustomersDataSet = CustomersDataSet.GetCustomers()
m_CustomersGrid.DataSource = m_CustomersBindingSource
m_CustomersBindingSource.DataSource = nwData.Customers

Then you can sort using the BindingSource.

CustomersBindingSource.Sort = "ContactName ASC"

And you can find using the BindingSource.

Dim index as integer = _
CustomersBindingSource.Find("CompanyName", CompanyNameTextBox.Text)
If index <-1 then 'it was found; move to that position
CustomersBindingSource.Position = index
End If

You could then populate:

CustomersBindingSource.Find("CompanyName", CompanyNameTextBox.Text)

with the keys pressed in the cell by capturing them by utilizing:

 Private Sub DataGridView1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyUp
        Dim dgv As DataGridView = TryCast(sender, DataGridView)

        If dgv IsNot Nothing Then

           'You will need some logic here to determine how long to wait between keyups 
           'Perhaps a timer that ticks every500 milliseconds and reset on keyup.  
e.KeyData
            End If
        End Sub

I found the original Biding Source Logic at : This Location

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号