Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8569977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:27:26+00:00 2026-06-11T18:27:26+00:00

hi im formulating my question now better. in the foreach command i get for

  • 0

hi im formulating my question now better.

in the foreach command i get for temp(save variable) values in an array. The values that i save in temp are from the datagridview cells.

in the next step, in the for command, i want to compare 2 strings, the string and the next string, if the fist string is bigger than the second, i want to change their positions. But there is the problem, they dont change positions they even get an empty value, and i cant understand why they get an empty value.

Im thinking that they get an empty value because of the foreach command, the index [i] just stays the same, but if i would put in i = i+1, the command would be out of bound.

Thank you

senc. NIko

foreach (DataGridViewRow row in dataGridView1.Rows)     
{
    if (row.Cells[i].Value == null)
    {
        //MessageBox.Show("This row is empty");
        break;
    }
    if (row.Cells[i].Value != null)
    {
        temp = row.Cells[i].Value.ToString();
        UnsortArray[i] = temp;
        i = i + 1;

    }
}

for (int a = 0; a < MaxZeilen; a++)
{
    if (i < MaxZeilen)
    {
        *if (String.Compare(UnsortArray[a], UnsortArray[a + 1]) > 0) 
        {
            UnsortArray[a] = temp;
            UnsortArray[a + 1] = temp2;
            temp = UnsortArray[a + 1];
            temp2 = UnsortArray[a];
        }*
    }
}

for (int i = 0; i < MaxZeilen; i++)
{
    UnsortArray[i] = SortArray[i];
    MessageBox.Show(UnsortArray[i]);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:27:27+00:00Added an answer on June 11, 2026 at 6:27 pm

    You’re backwards, assigning the array to your temp variables before assigning the temp variables:

    UnsortArray[a] = temp;
    UnsortArray[a + 1] = temp2;
    temp = UnsortArray[a + 1];
    temp2 = UnsortArray[a];
    

    Try:

    temp = UnsortArray[a + 1];
    temp2 = UnsortArray[a];
    UnsortArray[a] = temp;
    UnsortArray[a + 1] = temp2;
    

    And you’ve done it again here UnsortArray[i] = SortArray[i];. I think you mean SortArray[i] = UnsortArray[i];

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely re-formulating this question having learned that I was originally off track but
I had some problem formulating the question in the title, but i hope you
While formulating an answer to another SO question , I came across some strange
I'm having trouble formulating a SQL statement to return the values I want. I
I'm having trouble formulating a SQL query. I run the following: SELECT * FROM
I'm having some trouble formulating a findAll query for BeautifulSoup that'll do what I
I have a very basic question about populating listviews in android. Right now, if
I must admit I'm having trouble formulating this question, but I'll try my best
My question: How can my iPhone-app tell the iOS, that the user did select
I am having a hard time formulating my question so I'll just show by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.