DataGridView Sorting Problem
-
Mark Nischalke wrote:
What happens when there are more than three digits?
Um...you take 15 seconds to increase the size in function? Or set it to left-pad with zeros out to 20* places from the get-go and not worry about it? (* or whatever is reasonable)
Mark Nischalke wrote:
What happens when the business logic changes or the field changes?
Well, that changes more than this little bit, so why worry about it since a boatload of stuff will need to be rewritten, anyway? And, if that happened, you'd be rewriting any custom sorting in the program itself if you made your own comparer there. Me, I'd rather avoid that and just change a view.
GenJerDan wrote:
you'd be rewriting any custom sorting in the program itself if you made your own comparer there.
Not quite. Had similar requirements and wrote the comparer well enough the first time, no need to keep updating it.
I know the language. I've read a book. - _Madmatt
-
Yes, wait for .NET Framework 5.0 and hope they have implemented your specific sorting requirements into the DataGridView control.
I know the language. I've read a book. - _Madmatt
Daoist Coding and Sarcasm, I like it!
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-
A Dead ringer for Kate Winslett[^] -
And what if the data needs to be displayed as is without leading zeros?
I know the language. I've read a book. - _Madmatt
You can have a seperate column in the datatable that contains a normalized version of the display data. This normalized version could be used for sorting. Then, when you bind the grid to the table, you simply don't include this sort column in the bindings.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
You can have a seperate column in the datatable that contains a normalized version of the display data. This normalized version could be used for sorting. Then, when you bind the grid to the table, you simply don't include this sort column in the bindings.
A guide to posting questions on CodeProject[^]
Dave KreskowiakYes, of course. I was trying to point out to the OP is isn't as simple as just changing the data in the column.
I know the language. I've read a book. - _Madmatt
-
Daoist Coding and Sarcasm, I like it!
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-
A Dead ringer for Kate Winslett[^]Sarcasm? ;P
I know the language. I've read a book. - _Madmatt
-
And what if the data needs to be displayed as is without leading zeros?
I know the language. I've read a book. - _Madmatt
He asked for an easier solution and I suggested one. It's up to him to decide whether it works for his particular case. He didn't introduce that additional requirement, you did.
The difficult we do right away... ...the impossible takes slightly longer.
-
He asked for an easier solution and I suggested one. It's up to him to decide whether it works for his particular case. He didn't introduce that additional requirement, you did.
The difficult we do right away... ...the impossible takes slightly longer.
An "easy" solution that ignores potential pitfalls is not good advice, but, yes, it is up to the OP.
I know the language. I've read a book. - _Madmatt
-
Yes, of course. I was trying to point out to the OP is isn't as simple as just changing the data in the column.
I know the language. I've read a book. - _Madmatt
Yeah, some people just don't want to write code to solve problems anymore. They think that the .NET Framework can read minds and do everything you intended with just a few statements.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Dear ALL Now i have a col . contains for example the following PC1 PC2 PC10 PC100 , if u tried to sort it , it will be PC1 PC10 PC100 PC2 so how to make it sort as it sort numbers to be PC1 PC2 PC10 PC100 my datagridview is binded to a datasource so i can't use SortCompare(object sender, DataGridViewSortCompareEventArgs e) so any tips thanks all bye
well thx all well i guess the easiest way :omg: that i will recode my code by using the datagridview without the databinding so i can use SortCompare(object sender, DataGridViewSortCompareEventArgs e) thanks anyway all and thanks also to whom comment on my Q in a funny way:confused::confused: bye
-
Dear ALL Now i have a col . contains for example the following PC1 PC2 PC10 PC100 , if u tried to sort it , it will be PC1 PC10 PC100 PC2 so how to make it sort as it sort numbers to be PC1 PC2 PC10 PC100 my datagridview is binded to a datasource so i can't use SortCompare(object sender, DataGridViewSortCompareEventArgs e) so any tips thanks all bye