高效的 DataGridView 替代方案
Efficient DataGridView Alternative
我正在寻找 DataGridView 的有效替代品,最好是免费的。它必须能够按字母和数字对值进行排序,并且能够相对无缝地处理具有 13 列的数百行 - 我只需要添加一次行,但大部分数据(大约 9 行)将需要大约每半秒更新一次。
我尝试过使用 datagridview,但不幸的是,它的速度不足以满足我的需求——补充一下,实现的排序很糟糕;例如,数字排序:100,1009,102,102,106,1061,107,108,1115。
关于有效替代方案的任何建议?
谢谢!
设置 DoubleBuffered
DataGridView 将提高性能。
要了解有关此主题的更多信息,请参阅该维基百科 link 中的 "Double buffering in computer graphics" 部分:Multiple buffering。
来自维基百科:
It is difficult for a program to draw a display so that pixels do not
change more than once. For instance, when updating a page of text, it
is much easier to clear the entire page and then draw the letters than
to somehow erase all the pixels that are not in both the old and new
letters
您在评论中提到的 link 中标记的答案将完成这项工作
但它使用 Reflection
并且最好避免使用 Reflection
如果没有它也可以达到该结果。
更好的解决方案是创建您自己的自定义数据网格视图,设置 DoubleBuffered 并在您的 GUI 中实现自定义控件。
例如:
class MyCustomDataGridView: System.Windows.Forms.DataGridView
{
public MyCustomDataGridView(): base()
{
base.DoubleBuffered = true;
}
}
@Jonathana 太棒了!太感谢了!效果很好! :)
我为您的答案 +1,但由于我的代表少于 15 个,所以它没有任何效果……无论如何,这就是解决方案!
另外,至于排序,我真的需要它,因为它是程序的一部分原因……需要能够根据用户希望的方式进行排序……
将其添加到 SortCompare 方法中:
if (e.Column.Index > 0 && e.Column.Index <COLUMN_COUNT) //first column is text, default sort is fine..
{
e.SortResult = double.Parse(e.CellValue1.ToString()).CompareTo(double.Parse(e.CellValue2.ToString()));
e.Handled = true;
}
我正在寻找 DataGridView 的有效替代品,最好是免费的。它必须能够按字母和数字对值进行排序,并且能够相对无缝地处理具有 13 列的数百行 - 我只需要添加一次行,但大部分数据(大约 9 行)将需要大约每半秒更新一次。 我尝试过使用 datagridview,但不幸的是,它的速度不足以满足我的需求——补充一下,实现的排序很糟糕;例如,数字排序:100,1009,102,102,106,1061,107,108,1115。 关于有效替代方案的任何建议? 谢谢!
设置 DoubleBuffered
DataGridView 将提高性能。
要了解有关此主题的更多信息,请参阅该维基百科 link 中的 "Double buffering in computer graphics" 部分:Multiple buffering。
来自维基百科:
It is difficult for a program to draw a display so that pixels do not change more than once. For instance, when updating a page of text, it is much easier to clear the entire page and then draw the letters than to somehow erase all the pixels that are not in both the old and new letters
您在评论中提到的 link 中标记的答案将完成这项工作
但它使用 Reflection
并且最好避免使用 Reflection
如果没有它也可以达到该结果。
更好的解决方案是创建您自己的自定义数据网格视图,设置 DoubleBuffered 并在您的 GUI 中实现自定义控件。
例如:
class MyCustomDataGridView: System.Windows.Forms.DataGridView
{
public MyCustomDataGridView(): base()
{
base.DoubleBuffered = true;
}
}
@Jonathana 太棒了!太感谢了!效果很好! :) 我为您的答案 +1,但由于我的代表少于 15 个,所以它没有任何效果……无论如何,这就是解决方案! 另外,至于排序,我真的需要它,因为它是程序的一部分原因……需要能够根据用户希望的方式进行排序…… 将其添加到 SortCompare 方法中:
if (e.Column.Index > 0 && e.Column.Index <COLUMN_COUNT) //first column is text, default sort is fine..
{
e.SortResult = double.Parse(e.CellValue1.ToString()).CompareTo(double.Parse(e.CellValue2.ToString()));
e.Handled = true;
}