Click here to Skip to main content
15,896,063 members
Home / Discussions / C#
   

C#

 
GeneralRe: Message Box changing focus & moved to the back of the parent window Pin
honeyashu8-Aug-09 0:45
honeyashu8-Aug-09 0:45 
GeneralRe: Message Box changing focus & moved to the back of the parent window Pin
Luc Pattyn8-Aug-09 1:32
sitebuilderLuc Pattyn8-Aug-09 1:32 
GeneralRe: Message Box changing focus & moved to the back of the parent window Pin
honeyashu10-Aug-09 3:29
honeyashu10-Aug-09 3:29 
QuestionFlash on WebBrowser?? Pin
Muammar©7-Aug-09 22:32
Muammar©7-Aug-09 22:32 
AnswerSolved! Pin
Muammar©7-Aug-09 23:08
Muammar©7-Aug-09 23:08 
QuestionHow do you sort a listBox by number value rather than alphabetically Pin
Nathan Revka7-Aug-09 22:17
Nathan Revka7-Aug-09 22:17 
AnswerRe: How do you sort a listBox by number value rather than alphabetically Pin
Henry Minute8-Aug-09 0:01
Henry Minute8-Aug-09 0:01 
AnswerRe: How do you sort a listBox by number value rather than alphabetically Pin
Moreno Airoldi8-Aug-09 0:03
Moreno Airoldi8-Aug-09 0:03 
You can implement a custom type for Cards and override the CompareTo() method to implement custom sorting. Something like:

C#
        internal enum CardSuits
        {
            Spades = 0,
            Hearts,
            Diamonds,
            Clubs
        }

        internal enum CardValues
        {
            Two = 0,
            Three,
            Four,
            Five,
            Six,
            Seven,
            Eight,
            Nine,
            Ten,
            Jack,
            Queen,
            King,
            Ace
        }

        internal class Card : IComparable
        {
            internal CardSuits Suit;
            internal CardValues Value;

            internal Card(CardSuits Suit, CardValues Value)
            {
                this.Suit = Suit;
                this.Value = Value;
            }

            public int CompareTo(object obj)
            {
                int MyValue = (int)Value;
                Card OtherCard = (Card)obj;
                int OtherValue = (int)OtherCard.Value;
                return MyValue.CompareTo(OtherValue);
            }

            public override string ToString()
            {
                StringBuilder sb = new StringBuilder();
                switch (Value)
                {
                    case CardValues.Two:
                        sb.Append("Two");
                        break;
                    case CardValues.Three:
                        sb.Append("Three");
                        break;
                    case CardValues.Four:
                        sb.Append("Four");
                        break;
                    case CardValues.Five:
                        sb.Append("Five");
                        break;
                    case CardValues.Six:
                        sb.Append("Six");
                        break;
                    case CardValues.Seven:
                        sb.Append("Seven");
                        break;
                    case CardValues.Eight:
                        sb.Append("Eight");
                        break;
                    case CardValues.Nine:
                        sb.Append("Nine");
                        break;
                    case CardValues.Ten:
                        sb.Append("Ten");
                        break;
                    case CardValues.Jack:
                        sb.Append("Jack");
                        break;
                    case CardValues.Queen:
                        sb.Append("Queen");
                        break;
                    case CardValues.King:
                        sb.Append("King");
                        break;
                    case CardValues.Ace:
                        sb.Append("Ace");
                        break;
                    default:
                        sb.Append("???");
                        break;
                }
                sb.Append(" of ");
                switch (Suit)
                {
                    case CardSuits.Spades:
                        sb.Append("Spades");
                        break;
                    case CardSuits.Hearts:
                        sb.Append("Hearts");
                        break;
                    case CardSuits.Diamonds:
                        sb.Append("Diamonds");
                        break;
                    case CardSuits.Clubs:
                        sb.Append("Clubs");
                        break;
                    default:
                        sb.Append("???");
                        break;
                }
                return sb.ToString();
            }
        }

...

            List<Card>CardList = new List<Card>();
            CardList.Add(new Card(CardSuits.Hearts, CardValues.Three));
            CardList.Add(new Card(CardSuits.Clubs, CardValues.Queen));
            CardList.Add(new Card(CardSuits.Diamonds, CardValues.Nine));
            CardList.Add(new Card(CardSuits.Spades, CardValues.Ace));

            CardList.Sort();

            listBox1.DataSource = CardList;


2+2=5 for very large amounts of 2
(always loved that one hehe!)

AnswerRe: How do you sort a listBox by number value rather than alphabetically [modified] Pin
Luc Pattyn8-Aug-09 0:13
sitebuilderLuc Pattyn8-Aug-09 0:13 
QuestionHow do you sort a listBox by number value rather than alphabetically Pin
Nathan Revka7-Aug-09 22:17
Nathan Revka7-Aug-09 22:17 
QuestionSplit text and Store into Arry List Pin
M Riaz Bashir7-Aug-09 20:28
M Riaz Bashir7-Aug-09 20:28 
AnswerRe: Split text and Store into Arry List Pin
Abhijit Jana7-Aug-09 21:42
professionalAbhijit Jana7-Aug-09 21:42 
GeneralRe: Split text and Store into Arry List Pin
OriginalGriff7-Aug-09 22:04
mveOriginalGriff7-Aug-09 22:04 
GeneralRe: Split text and Store into Arry List Pin
Abhijit Jana7-Aug-09 22:17
professionalAbhijit Jana7-Aug-09 22:17 
AnswerRe: Split text and Store into Arry List Pin
Arindam Sinha7-Aug-09 21:58
Arindam Sinha7-Aug-09 21:58 
AnswerRe: Split text and Store into Arry List Pin
Mycroft Holmes7-Aug-09 22:07
professionalMycroft Holmes7-Aug-09 22:07 
QuestionCrystal Report Error... Pin
Rahul DSG7-Aug-09 20:19
Rahul DSG7-Aug-09 20:19 
QuestionC# Save Application Layout on application exit and reload it on application start. [modified] Pin
shaktisinh7-Aug-09 18:01
shaktisinh7-Aug-09 18:01 
AnswerRe: C# Save Application Layout on application exit and reload it on application start. Pin
N a v a n e e t h7-Aug-09 18:15
N a v a n e e t h7-Aug-09 18:15 
AnswerRe: C# Save Application Layout on application exit and reload it on application start. Pin
stancrm7-Aug-09 19:17
stancrm7-Aug-09 19:17 
AnswerRe: C# Save Application Layout on application exit and reload it on application start. Pin
Arindam Sinha7-Aug-09 22:03
Arindam Sinha7-Aug-09 22:03 
GeneralRe: C# Save Application Layout on application exit and reload it on application start. Pin
shaktisinh12-Aug-09 3:27
shaktisinh12-Aug-09 3:27 
GeneralMessage Removed Pin
13-Aug-09 0:35
shaktisinh13-Aug-09 0:35 
GeneralRe: C# Save Application Layout on application exit and reload it on application start. Pin
Arindam Sinha15-Aug-09 13:14
Arindam Sinha15-Aug-09 13:14 
GeneralRe: C# Save Application Layout on application exit and reload it on application start. Pin
shaktisinh16-Aug-09 19:40
shaktisinh16-Aug-09 19: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.