Reputation: 161
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);
Upvotes: 2
Views: 207
Reputation: 6259
A shot in the dark: You say you have six radio buttons, but you're only checking five and assigning the sort column by that. If five of your sorts are working and one isnt, maybe that's the button you omitted?
It is difficult to tell if this really the problem. The names of those fields are very unclear - in your mind is it "radio button 6" or "the button to sort by region name"? Name something for what it means.
Upvotes: 1