我有一个文本框过滤器搜索,我想要一个按钮来计算在grideview中找到的textbox_search单词的数量,并在表单上的标签中显示总数。
Dim d1 As New DataTable
Dim dv As New DataView(d1)
dv.RowFilter = String.Format(" Name like '%{0}%'", TextBox1.Text)
DataGridView1.DataSource = dv
答案 0 :(得分:0)
如果您只想计算使用DataView
属性过滤DataView.RowFilter
后返回的行数,则可以使用DataView.Count
属性或DataGridView.Rows.Count
属性,例如这个:
Dim d1 As New DataTable
Dim dv As New DataView(d1)
' Using interpolated string to set up the filter.
dv.RowFilter = $"Name LIKE '%{TextBox1.Text}%'"
DataGridView1.DataSource = dv
CountByDvLabel.Text = dv.Count.ToString()
CountByDgvLabel.Text = DataGridView1.Rows.Count.ToString()