Friday, August 20, 2010

Give me the complete code pls.in VB.Net?

What I have is a datagrid on my form populated with various pieces of


information. What I would like is to be able to start typing and have


the datagrid move to the thing I'm typing if it exists.





For example given the list:





Ant


Cat


Dog


Dolphin


Puppy


Snake


Snail


Zebra





If I started typing ';Do'; then the list would move to Dog..and then if I


typed a ';Dol'; the list would move to Dolphin. It's the same way all


the file searching works in windows.





Any ideas how I would do this guys?Give me the complete code pls.in VB.Net?
refer this field to a data source...


listen, check the MSDN, u can find everything thereGive me the complete code pls.in VB.Net?
Hello, i'm sure there many ways to skin a cat when it comes to programming.. one way of doing it.. would be.. first create a dataset because it supports Select statement then add datatable to it with all your names. after that set datasource to the table.. and monitor keypress in text box.. long story short.





Public Class Form1





Private DTS As New DataSet





Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Dim DT As New DataTable(';tblData';)


DT.Columns.Add(';Name';)


DT.Columns.Add(';Index';)





With DT.Rows


.Add(';Ant';, ';0';)


.Add(';Cat';, ';1';)


.Add(';Dog';, ';2';)


.Add(';Dolphin';, ';3';)


.Add(';Puppy';, ';4';)


.Add(';Snake';, ';5';)


.Add(';Snail';, ';6';)


.Add(';Zebra';, ';7';)


End With





DataGridView1.DataSource = DT


DataGridView1.ClearSelection()


DTS.Tables.Add(DT)


End Sub





Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp


Dim DR() As DataRow


Dim Index As Integer





DR = DTS.Tables(';tblData';).Select(';[Name] LIKE ''; %26amp; TextBox1.Text %26amp; ';*'';)





If DR.Length %26gt; 0 And TextBox1.Text.Length %26gt; 0 Then


DataGridView1.ClearSelection()


Index = DR(0)(';Index';)


DataGridView1.Rows(Index).Selected = True


Else


DataGridView1.ClearSelection()


End If


End Sub


End Class





in this case, i assigned an index to each name, it will select only the first match, you can modify it to select all matches.





another one, simply add that to your textbox keyup event





Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp


Dim iFound As Integer = -1


Dim myRow As DataGridViewRow





DataGridView1.AllowUserToAddRows = False


DataGridView1.ClearSelection()





For Each myRow In DataGridView1.Rows


iFound = myRow.Cells(';Name';).Value.ToString.Index鈥?br>

If iFound %26gt;= 0 And TextBox1.Text.Length %26gt; 0 Then


myRow.Selected = True


Exit Sub


End If


Next





DataGridView1.ClearSelection()


DataGridView1.AllowUserToAddRows = False


End Sub





you can modify it so it's not case sensative.

No comments:

Post a Comment