exchange the columns in Datagridview

  • Thread starter Thread starter cloud
  • Start date Start date
C

cloud

Hello all,
The datasourse for the datagridview is from excel and text file
Is it possible to shift the datagridview columns. I mean to exchange
the columns after getting the data into the DGV

thank u for any response
 
Yes you can.

DataGridView1.Columns("Column1").DisplayIndex = 5
DataGridView1.Columns("Column2").DisplayIndex = 6
DataGridView1.Columns("Column3").DisplayIndex = 4
DataGridView1.Columns("Column4").DisplayIndex = 1
DataGridView1.Columns("Column5").DisplayIndex = 3
DataGridView1.Columns("Column6").DisplayIndex = 2

And you can change the text of the cell headers

DataGridView1.Columns("Column1").HeaderText = "New Header Text 1"
DataGridView1.Columns("Column2").HeaderText = "New Header Text 2"
DataGridView1.Columns("Column3").HeaderText = "New Header Text 3"
DataGridView1.Columns("Column4").HeaderText = "New Header Text 4"
DataGridView1.Columns("Column5").HeaderText = "New Header Text 5"
DataGridView1.Columns("Column6").HeaderText = "New Header Text 6"
 
Yes you can.

 DataGridView1.Columns("Column1").DisplayIndex = 5
        DataGridView1.Columns("Column2").DisplayIndex = 6
        DataGridView1.Columns("Column3").DisplayIndex = 4
        DataGridView1.Columns("Column4").DisplayIndex = 1
        DataGridView1.Columns("Column5").DisplayIndex = 3
        DataGridView1.Columns("Column6").DisplayIndex = 2

And you can change the text of the cell headers

DataGridView1.Columns("Column1").HeaderText = "New Header Text 1"
        DataGridView1.Columns("Column2").HeaderText = "New Header Text 2"
        DataGridView1.Columns("Column3").HeaderText = "New Header Text 3"
        DataGridView1.Columns("Column4").HeaderText = "New Header Text 4"
        DataGridView1.Columns("Column5").HeaderText = "New Header Text 5"
        DataGridView1.Columns("Column6").HeaderText = "New Header Text 6"

I dont want to change in the program. When we run the program
for eg: if we double click any cell in the datagridview , we can edit
the cell. My question is , is it also possible to edit the headers
there.
Second is..at run time with mouse , is it possible to exchange the
columns....
 
Back
Top