Click here to Skip to main content
15,889,281 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: I think I got it Pin
jkirkerx24-Oct-14 6:42
professionaljkirkerx24-Oct-14 6:42 
QuestionHow to Populate DataGridViewComboBox with a DataTable Pin
Benniiit22-Oct-14 3:36
Benniiit22-Oct-14 3:36 
SuggestionRe: How to Populate DataGridViewComboBox with a DataTable Pin
Richard Deeming22-Oct-14 4:32
mveRichard Deeming22-Oct-14 4:32 
QuestionlistItem to show text box Pin
byka20-Oct-14 7:04
byka20-Oct-14 7:04 
GeneralSort methodes idees wanted Pin
JR21220-Oct-14 1:09
JR21220-Oct-14 1:09 
GeneralRe: Sort methodes idees wanted Pin
Richard Deeming20-Oct-14 1:58
mveRichard Deeming20-Oct-14 1:58 
GeneralRe: Sort methodes idees wanted Pin
Eddy Vluggen20-Oct-14 1:59
professionalEddy Vluggen20-Oct-14 1:59 
AnswerRe: Sort methodes idees wanted Pin
Manfred Rudolf Bihy20-Oct-14 2:24
professionalManfred Rudolf Bihy20-Oct-14 2:24 
I'd stick with the "one method" approach or rather one interface. There is an article here on CP that introduces you to the usage of IComparable and IComparer. For the sake of flexibility I'd say you use the IComparer method. "Why is that?" you may ask. I'll try to explain.

Using the IComparable interface will make it hard to sort items on a flexible number of fields with both ascending and descding support for each field. The CompareTo method in the Icomparable interface only allows you to compare to another item of that type, but does not let you pass configuration information about the fields involved and the sort order (ascending/descending).

Using a dedicated IComparer class implementation remedies the above mentioned problems. The implementation of your special class that implements IComparer could be configured with the correct sequence in which to compare the fields and a factor of 1 or -1 for ascending or descending.

Here is how to proceed:


  1. Compare the fields in the sequence configured.
  2. You only need to compare another field if all fields previous in the sequence returned a comparison value of 0 (== they were all equal to another).
  3. Your Compare(a, b) method should return the value of the first non-zero compare operation multiplied by the factor 1 for ascending or by -1 for descending, depending what has been configured for the field currently being compared.
  4. If all fields compare as equal to each other return then 0. How this case is handled depends on whether the sorting algorithm is stable or not.


Regards,

Manfred

"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian


GeneralRe: Sort methodes idees wanted Pin
JR21221-Oct-14 0:29
JR21221-Oct-14 0:29 
GeneralRe: Sort methodes idees wanted Pin
Manfred Rudolf Bihy21-Oct-14 0:52
professionalManfred Rudolf Bihy21-Oct-14 0:52 
QuestionHelp needed creating a form based on a vbscript Pin
Malbordio19-Oct-14 6:25
Malbordio19-Oct-14 6:25 
AnswerRe: Help needed creating a form based on a vbscript Pin
Dave Kreskowiak23-Oct-14 10:00
mveDave Kreskowiak23-Oct-14 10:00 
Questionhow to open password protected .pdf file in vb 6.0 Pin
kirtitripathy17-Oct-14 21:25
kirtitripathy17-Oct-14 21:25 
AnswerRe: how to open password protected .pdf file in vb 6.0 Pin
Dave Kreskowiak18-Oct-14 4:34
mveDave Kreskowiak18-Oct-14 4:34 
QuestionHow to search in a List (of structure) Pin
dilkonika14-Oct-14 4:52
dilkonika14-Oct-14 4:52 
AnswerRe: How to search in a List (of structure) Pin
Eddy Vluggen14-Oct-14 5:39
professionalEddy Vluggen14-Oct-14 5:39 
QuestionVBScript Connect to Database across Internet Pin
JM7613-Oct-14 4:22
JM7613-Oct-14 4:22 
AnswerRe: VBScript Connect to Database across Internet Pin
Eddy Vluggen13-Oct-14 7:34
professionalEddy Vluggen13-Oct-14 7:34 
GeneralRe: VBScript Connect to Database across Internet Pin
JM7613-Oct-14 7:39
JM7613-Oct-14 7:39 
GeneralRe: VBScript Connect to Database across Internet Pin
Eddy Vluggen13-Oct-14 8:23
professionalEddy Vluggen13-Oct-14 8:23 
GeneralRe: VBScript Connect to Database across Internet Pin
JM7613-Oct-14 9:12
JM7613-Oct-14 9:12 
GeneralRe: VBScript Connect to Database across Internet Pin
Eddy Vluggen13-Oct-14 10:42
professionalEddy Vluggen13-Oct-14 10:42 
AnswerRe: VBScript Connect to Database across Internet Pin
Bernhard Hiller19-Oct-14 22:42
Bernhard Hiller19-Oct-14 22:42 
GeneralRe: VBScript Connect to Database across Internet Pin
JM7620-Oct-14 6:09
JM7620-Oct-14 6:09 
QuestionBind a listbox to a list of structure Pin
dilkonika11-Oct-14 8:40
dilkonika11-Oct-14 8:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.