How to Find data in dataview?

isawa

Active member
Joined
Oct 3, 2005
Messages
25
Programming Experience
Beginner
I want to know How to find data in dataview? Like a dataview.RowFilter for ex.

Dim vDataView As New DataView(Me.AllDataSet.type)
If Me.ToolStripTextBox_Search.Text <> "" Then
Me.ToolStripStatusLabel1.Text = Me.ToolStripComboBox_Fields.Text & " Like '" & Me.ToolStripTextBox_Search.Text & "%'"
vDataView.Find = SendField(Me.ToolStripComboBox_Fields.SelectedIndex) & " Like '" & Me.ToolStripTextBox_Search.Text & "%'"
End If
Me.DataGridView_Search.DataSource = vDataView

...

:confused:
 
Generally speaking you don't need to create a DataView object. Every DataTable is associated with a DataView by default in its DefaultView property. If you simply bind your DataTable to a DataGridView and set its DefaultView.RowFilter property the grid will reflect the change. The DefaultView property of a DataTable is very similar to its Rows property, which is a DataRowCollection object. The DefaultView has a Count property, just like the Rows property, and you can iterate over the DataRowView objects in a DataView just like you can iterate over the DataRow objects in a DataRowCollection. You access a field in a DataRowView just like you do in a DataRow as well, either by index or ColumnName, e.g.
VB.NET:
myDataTable.DefaultView.RowFilter = "LastName = 'Smith'"

For Each row As DataRowView In myDataTable.DefaultView
    MessageBox.Show(row("LastName"))
Next row
 
Back
Top