1

我有一个使用 dataGridGrid 的 C# winForm,我每秒接收大约 20 条消息,我有大约 1000 行......是否有任何“快速查找”方法和/或设计模式可以让我找到特定的行不遍历 dataGridView.Rows 集合?这似乎是一种非常低效的方法,但除了我“认为”是一个循环的 dataGridView.Rows.Remove() 之外,我似乎找不到其他任何东西,对吗?有人可以帮我吗?

提前致谢,

-DA

4

2 回答 2

0

您可能可以使用一些 LINQ 来查找该行,因为它是未绑定的。我不知道你在匹配什么,但希望这会有所帮助:

var x = (from DataGridViewRow r in dataGridGrid.Rows 
         where r.Cells[SomeCellIndex_OrName].Value == "Some Value"
         select r).FirstOrDefault();

if (x != null ) {

  //Do Something to x
  // x is your row
  // x == null when not found
}
于 2013-03-06T00:20:14.500 回答
0

如果我正确理解您的问题,您想在 DataGridView 中查找特定行并删除它们。假设您正在使用 DataGridView 尝试将其 DataSource 绑定到 BindingSource ,然后您可以像这样找到(最后添加的)行:

    BindingSource.Position = BindingSource.Find(string PropertyName, object key);

要删除选定的行,请将您的位置保存到变量中,然后:

    DataGridView.Rows.RemoveAt(your variable);

希望有帮助

于 2013-03-06T11:35:07.923 回答