locked
Arranging the column in droped index value RRS feed

  • Question

  • hi,

        I want to update the column(reorder) after i drop a column inside the datagridview. The updation is based on the column index value. when i drop the column to the datagrid it get add at the last of the datagridview. Have any logic to over come this.....?  so that i droped it should display at the droped position....

     

    Wednesday, June 18, 2008 11:39 AM

Answers

  • Hi,

     

    Try the following untested code:

     

    Code Snippet

    dataGridView1.AutoGenerateColumns = false;

    this.dataGridView1.Columns["ColName"].DisplayIndex = 4;

    // you may also have to readjust the display index of other columns.

     

     

     

    HTH,

    Suprotim Agarwal

     

    Wednesday, June 18, 2008 11:54 AM

All replies

  • Hi,

     

    Try the following untested code:

     

    Code Snippet

    dataGridView1.AutoGenerateColumns = false;

    this.dataGridView1.Columns["ColName"].DisplayIndex = 4;

    // you may also have to readjust the display index of other columns.

     

     

     

    HTH,

    Suprotim Agarwal

     

    Wednesday, June 18, 2008 11:54 AM
  • the code is working but it work only one time (ie) only last drop column is rearranged, when another new column was  dropped the new column get populate in the droped position but the previously droped column is went to last. I want the previously dropped column should not get changed even  after i droped new one.

     

    Thursday, June 19, 2008 10:56 AM
  • Hi,

     

    Drop the code shared earlier in a seperate function. Then when you add a new column, call that function to rearrange the columns in the positions you want.

     

    HTH,

    Suprotim Agarwal

     

    Thursday, June 19, 2008 11:20 AM
  • Hi,

     

          But i have problem in column index when i add a column using the above code the column is added but the column index of the column is not get changed. For example when i drop  a column between the columnindex 1 and columnindex 2 the column get added between 1 and 2, but the column index of newly dropped column is became 3 so the order is like this

     

              columnIndex1,columnIndex3,columnIndex2

     

    But i want after dropping the column the columnindex must change automatically

     

                  after dropping the columnindex of 3 must become 2 when it come to second column and similarly the columnindex of 2 become 3 when it moves to third position.

     

     

    Is it possible....?  

    Friday, June 20, 2008 5:06 AM
  • Why not using DataGridView.Columns.Insert method to insert the column to the index you need?

    Friday, June 20, 2008 10:51 AM
  • ya i got it finished thank u

     

    Friday, June 20, 2008 11:49 AM
  • Hi,

     

    Can you share your solution for the benefit of future users having same issue.

     

    HTH,

    Suprotim Agarwal

     

    Friday, June 20, 2008 12:34 PM
  • sure, but now again i met with some logical error after i finished i will do

     

    Monday, June 23, 2008 3:15 AM