0

Hi all,

Im trying to work something out.

I have the following:-

datagridview 1

column1 column2
1 56
2 76
3 23
4 13
5 24


I want to create another datagridview based on the datagridview 1 but i would like to have a loop that keeps column1 as it is but has column2 backwards or reverse ie 1: 24, 2: 13 etc.I need a loop because there is more data than the example.

Thanks

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by andrewll2
0
void Change()
        {
            int hp1 = 0;
            int hp2 = 0;
            // setting the values to equal in both datagrid views (setting the same as the datasource)
            dataGridView1.DataSource = dataGridView2.DataSource;
            /*___________________*/
            //changing nth row's cell in every second column to (everyrow-n)th row's cell
            while(hp1 < dataGridView2.ColumnCount/2)
            {
            while (hp2 < dataGridView2.Rows.Count)
            {
                dataGridView1[hp1 * 2, hp2] = dataGridView2[hp1 * 2, dataGridView2.Rows.Count - hp2];
                hp2++;
            }
            hp2 = 0;
            hp1++;
            }
            /*>End of task^^<*/
        }

This should do the trick without knowing the ammount of the dataGridView's data.
If you have a problem with it please tell me about it ,in fact i have hardly worked with databases before,but this code must work^^.
~Happy Coding
Andrew

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.