Sorting by Name (alphabetic)
I have a small application with two arrays.  One array is the names, one array is the scores.  I have the below code in a "sort" button.  There are also 6 radio buttons that sort by different ways.  5 of these buttons work, but I cannot seem to get the sort by "Region Name" working.  Sometimes when I enter two rows into the arrays it works, sometimes not.  I have been trying to figure this out for nearly an hour but cannot seem to figure out why it will not work.  Any ideas out there?


    private void btnSort_Click(object sender, EventArgs e)
            {
                int n;
                decimal temp;
                int sortCol = 0;
                string ntemp;
                bool swapFlag;
    
    
                if (rb1.Checked)
                    sortCol = 0;
    
                if (rb2.Checked)
                    sortCol = 1;
    
                if (rb3.Checked)
                    sortCol = 2;
    
                if (rb4.Checked)
                    sortCol = 3;
    
                if (rbTotal.Checked)
                    sortCol = 4;
    
                do
                {
                    swapFlag = false;
                    for (n = 0; n < lastIndexUsed; n++)
                    {
                        if(quarters[n,sortCol] < quarters[n+1, sortCol])
                            {
    
                            //column 4
                                temp = quarters[n, 4];
                                quarters[n, 4] = quarters[n + 1, 4];
                                quarters[n+1, 4] = temp; 
    
                            //col 3
                                temp = quarters[n, 3];
                                quarters[n, 3] = quarters[n + 1, 3];
                                quarters[n + 1, 3] = temp; 
    
                            //col 2
    
                                temp = quarters[n, 2];
                                quarters[n, 2] = quarters[n + 1, 2];
                                quarters[n + 1, 2] = temp;
    
                            // col 1
                                temp = quarters[n, 1];
                                quarters[n, 1] = quarters[n + 1, 1];
                                quarters[n + 1, 1] = temp;
    
                            //col 0
                                temp = quarters[n, 0];
                                quarters[n, 0] = quarters[n + 1, 0];
                                quarters[n + 1, 0] = temp;
    
                            //name
    
                                ntemp = Branch[n];
                                Branch[n] = Branch[n + 1];
                                Branch[n + 1] = ntemp;
    
                                swapFlag = true;
    
                            }//endif
    
                    }//for end
    
                } while (swapFlag);
Sorting by Name (alphabetic)
===

I have a small application with two arrays.  One array is the names, one array is the scores.  I have the below code in a "sort" button.  There are also 6 radio buttons that sort by different ways.  5 of these buttons work, but I cannot seem to get the sort by "Region Name" working.  Sometimes when I enter two rows into the arrays it works, sometimes not.  I have been trying to figure this out for nearly an hour but cannot seem to figure out why it will not work.  Any ideas out there?


    private void btnSort_Click(object sender, EventArgs e)
            {
                int n;
                decimal temp;
                int sortCol = 0;
                string ntemp;
                bool swapFlag;
    
    
                if (rb1.Checked)
                    sortCol = 0;
    
                if (rb2.Checked)
                    sortCol = 1;
    
                if (rb3.Checked)
                    sortCol = 2;
    
                if (rb4.Checked)
                    sortCol = 3;
    
                if (rbTotal.Checked)
                    sortCol = 4;
    
                do
                {
                    swapFlag = false;
                    for (n = 0; n < lastIndexUsed; n++)
                    {
                        if(quarters[n,sortCol] < quarters[n+1, sortCol])
                            {
    
                            //column 4
                                temp = quarters[n, 4];
                                quarters[n, 4] = quarters[n + 1, 4];
                                quarters[n+1, 4] = temp; 
    
                            //col 3
                                temp = quarters[n, 3];
                                quarters[n, 3] = quarters[n + 1, 3];
                                quarters[n + 1, 3] = temp; 
    
                            //col 2
    
                                temp = quarters[n, 2];
                                quarters[n, 2] = quarters[n + 1, 2];
                                quarters[n + 1, 2] = temp;
    
                            // col 1
                                temp = quarters[n, 1];
                                quarters[n, 1] = quarters[n + 1, 1];
                                quarters[n + 1, 1] = temp;
    
                            //col 0
                                temp = quarters[n, 0];
                                quarters[n, 0] = quarters[n + 1, 0];
                                quarters[n + 1, 0] = temp;
    
                            //name
    
                                ntemp = Branch[n];
                                Branch[n] = Branch[n + 1];
                                Branch[n + 1] = ntemp;
    
                                swapFlag = true;
    
                            }//endif
    
                    }//for end
    
                } while (swapFlag);