exchange the columns in Datagridview

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
 
A

Aaron

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"
 
C

cloud

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top