I'm looking for an efficient alternative to the DataGridView, preferably free. It must be capable of sorting values both alphabetically, and numerically, and be able to handle hundreds of rows with 13 columns relatively seamlessly - I only need to add the rows once, but much of the data (9 rows or so) will require to be updated about every half second. I've tried with datagridview, but unfortunately, it's just not fast enough for my needs - to add, the implemented sorting is terrible; for example, numerical sorting: 100,1009,102,102,106,1061,107,108,1115. Any suggestions on an effective alternative? Thank you!
-
1did you tried to set `DoubleBuffered` to your datagridview? (it can extremely improve the performance ). – Jonathan Applebaum Jul 17 '17 at 22:33
-
@jonathana WOW! Holy crap! Thank you so much! I I just looked it up, and set it from the code in this: https://stackoverflow.com/questions/4255148/how-to-improve-painting-performance-of-datagridview What a difference!! That's a big help! Now, is there anything special you might suggest for the sorting problem? – john zidr Jul 18 '17 at 05:17
-
Is the DGV data-bound? – TaW Jul 18 '17 at 06:44
-
@johnzidr, I glad i could help, please see my full answer, please mark it as an answer if you find it useful. – Jonathan Applebaum Jul 18 '17 at 07:59
-
as for the sorting, why not to sort the data before you enter it to the datagridview? also this will extremely effect the speed, every manipulation in graphic control (ie datagridview) is very slow compare to manipulation in some data structure field (`List`,`Datatable` etc..) – Jonathan Applebaum Jul 18 '17 at 13:18
2 Answers
Setting DoubleBuffered
of the DataGridView will improve the performance.
to learn more about this topic please refer to the "Double buffering in computer graphics" section in that wikipedia link: Multiple buffering.
from wikipedia:
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
the marked answer in the link you mentioned in your comment will do the job
but it uses Reflection
and it is better avoid using Reflection
when it is possible to achieve that result without it.
a better solution is to create your own custom datagridview, set the DoubleBuffered and implement the custom control in your GUI.
for example:
class MyCustomDataGridView: System.Windows.Forms.DataGridView
{
public MyCustomDataGridView(): base()
{
base.DoubleBuffered = true;
}
}

- 5,738
- 4
- 33
- 52
@Jonathana Awesome! Thank you so much! Works great! :) I +1'ed your answer, but being I have less than 15 rep, it has no effect.... Regardless, that's the solution! Also, as for the sort, I really need it as it's a part of the reason for the program... Needs to be able to sort according to how the user wants it to be.. Added this into the SortCompare method:
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;
}

- 3
- 1