【问题标题】:Count occurrences found in GridView of word entered in TextBox计算在 TextBox 中输入的单词在 GridView 中出现的次数
【发布时间】:2018-11-28 12:34:27
【问题描述】:

我有一个文本框过滤器搜索,我想要一个按钮来计算在 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

【问题讨论】:

  • 请试着更好地解释你想要什么,你做的方式,不是很清楚你在问什么。
  • 是的,当我搜索任何 company_name 时,gridview 中的所有数据都会出现,我不知道我搜索的所有 company_name 的数量。

标签: vb.net sql-server-2012


【解决方案1】:

如果您只想统计过滤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()

【讨论】:

  • 感谢您的回复
  • 图书馆,感谢您的回答的最佳方式是通过单击复选标记 (✓) 将其标记为已接受。但只有在某些回复回答了您最初的问题时才这样做。当您达到 15 个声望点时,您还可以vote up 寻求答案或问题。请参阅:Someone answered me 和 Why vote?。也可以通过tour 来初步了解网站的运作方式。
  • 我的回复是否回答了您最初的问题?
猜你喜欢
  • 2021-10-07
  • 1970-01-01
  • 2015-05-23
  • 2011-08-04
  • 2021-11-17
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
相关资源
最近更新 更多