Click here to Skip to main content
15,914,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: Tristate checkboxes in TreeView? Pin
Joel Lucsy22-Feb-06 13:21
Joel Lucsy22-Feb-06 13:21 
QuestionVB to C# codes Pin
superPaul10121-Feb-06 8:34
superPaul10121-Feb-06 8:34 
AnswerRe: VB to C# codes Pin
Wjousts21-Feb-06 8:38
Wjousts21-Feb-06 8:38 
GeneralRe: VB to C# codes Pin
superPaul10121-Feb-06 8:41
superPaul10121-Feb-06 8:41 
GeneralRe: VB to C# codes Pin
Wjousts21-Feb-06 8:46
Wjousts21-Feb-06 8:46 
GeneralRe: VB to C# codes Pin
superPaul10121-Feb-06 8:50
superPaul10121-Feb-06 8:50 
AnswerRe: VB to C# codes Pin
Dave Doknjas21-Feb-06 15:11
Dave Doknjas21-Feb-06 15:11 
QuestionWeird IComparer behavor in DataGridView Pin
Wjousts21-Feb-06 8:25
Wjousts21-Feb-06 8:25 
I have a DataGridView control on a form which is bound to a class that is derived from CollectionBase and implements IBindingList. This works okay except that the sorting acts really strangely in certain situations. To sort my class I implement IBindingList.ApplySort and in the method I use CollectionBase.InnerList.Sort and pass it an instance of a class that implements IComparer to sort the data objects in my list. The implementation of the IComparer.Compare method is relatively straightforward:

object a = MyType.GetProperty(PropertyName).GetValue(x, null);
object b = MyType.GetProperty(PropertyName).GetValue(y, null);

if (a != null && b == null)
    return 1;

if (a == null && b != null)
    return -1;

if (a == null && b == null)
    return 0;

return ((IComparable)a).CompareTo(b);


Now this sort of works okay. For example, if my data object has properties a, b, and c which are displayed on the DataGridView like this:
a    b    c
100  1    1
90   2    1
80   3    1
70   4    1
60   5    1
50   6    1
40   7    1


And I click on the header for row a I get this:
a    b    c
40   7    1
50   6    1
60   5    1
70   4    1
90   3    1
90   2    1
100  1    1


And if I click it again I get back to the original. So far so good. If I click on column b, I get the expected behavor too. However, if I click on column c (where all the values are the same) I get this:
a    b    c
60   5    1
50   6    1
40   7    1
70   4    1
100  1    1
90   2    1
80   3    1

Clicking a second time gets me to the second table above. Clicking a third times gives me this:
a    b    c
80   3    1
90   2    1
100  1    1
70   4    1
40   7    1
50   6    1
60   5    1

And finally, clicking a fourth time gets be back to the original order.
Does anybody have any idea what is going on here and how I can avoid it? This doesn't seem to ever happen if I use a DataTable as a data source.
QuestionApp in Taskbar like Media Player Pin
DeepToot21-Feb-06 7:21
DeepToot21-Feb-06 7:21 
AnswerRe: App in Taskbar like Media Player Pin
hard.disk21-Feb-06 8:01
hard.disk21-Feb-06 8:01 
GeneralRe: App in Taskbar like Media Player Pin
DeepToot21-Feb-06 8:04
DeepToot21-Feb-06 8:04 
QuestionToolstripLabel rendering Pin
Ravi Bhavnani21-Feb-06 7:14
professionalRavi Bhavnani21-Feb-06 7:14 
QuestionGetting the Serial Key Pin
superPaul10121-Feb-06 7:10
superPaul10121-Feb-06 7:10 
QuestionHow to register ActiveX contorl Pin
papa198021-Feb-06 6:10
papa198021-Feb-06 6:10 
QuestionExtracting information from URLs Pin
hasanali0021-Feb-06 6:09
hasanali0021-Feb-06 6:09 
AnswerRe: Extracting information from URLs Pin
Wjousts21-Feb-06 8:08
Wjousts21-Feb-06 8:08 
QuestionAdd IMessageFilter to COM Pin
jerryyag21-Feb-06 5:42
jerryyag21-Feb-06 5:42 
QuestionHow do I create a videoplayer? Pin
ChevyVanDude21-Feb-06 5:02
ChevyVanDude21-Feb-06 5:02 
QuestionMultithreading problem Pin
Le centriste21-Feb-06 4:50
Le centriste21-Feb-06 4:50 
AnswerRe: Multithreading problem Pin
Alvaro Mendez21-Feb-06 6:14
Alvaro Mendez21-Feb-06 6:14 
AnswerRe: Multithreading problem Pin
Judah Gabriel Himango21-Feb-06 6:21
sponsorJudah Gabriel Himango21-Feb-06 6:21 
GeneralRe: Multithreading problem Pin
Le centriste21-Feb-06 6:35
Le centriste21-Feb-06 6:35 
GeneralRe: Multithreading problem Pin
Judah Gabriel Himango21-Feb-06 6:56
sponsorJudah Gabriel Himango21-Feb-06 6:56 
GeneralRe: Multithreading problem Pin
Le centriste21-Feb-06 7:10
Le centriste21-Feb-06 7:10 
AnswerSOLVED (Unrelated to multithreading) Pin
Le centriste21-Feb-06 7:11
Le centriste21-Feb-06 7:11 

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.