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]);
}