1 Attachment(s)
[RESOLVED] Column order in DGV
I have the following form:
Attachment 153613
What I would like to do is have the last column be the second column and I am unable to figure out how to accomplish this. In the table adapter the last column is actually column 19 (of 19).
It appears to me, from this, that the columns can only be displayed in the order the columns are set in the tableadapter. That being the case, I have no idea how one would change the order of the columns so that I can arrange the columns in the DGV in the order I want them. I do know that I can change column order in a databound DGV using the DGV Task Window, but this cannot be applied for this particular DGV.
Code:
Private Sub DocChangeListLoad()
With dgvList
.DefaultCellStyle.Font = New Font("Times New Roman", 11)
.DefaultCellStyle.ForeColor = Color.Black
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
dgvList.DataSource = Me._MasterBase5_0DataSet
dgvList.DataMember = "tblChangeRequest"
With dgvList.Columns(0)
.Visible = True
.Width = 100
.HeaderText = "Change ID"
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
With dgvList.Columns(19)
.Visible = True
.Width = 100
.HeaderText = "Document ID"
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
With dgvList.Columns(1)
.Visible = True
.Width = 250
.HeaderText = "Title/Name"
End With
With dgvList.Columns(2)
.Visible = True
.Width = 100
.HeaderText = "Revision"
End With
dgvList.Columns(3).Visible = False
dgvList.Columns(4).Visible = False
dgvList.Columns(5).Visible = False
dgvList.Columns(6).Visible = False
dgvList.Columns(7).Visible = False
dgvList.Columns(8).Visible = False
dgvList.Columns(9).Visible = False
dgvList.Columns(10).Visible = False
dgvList.Columns(11).Visible = False
dgvList.Columns(12).Visible = False
dgvList.Columns(13).Visible = False
dgvList.Columns(14).Visible = False
dgvList.Columns(15).Visible = False
dgvList.Columns(16).Visible = False
dgvList.Columns(17).Visible = False
dgvList.Columns(18).Visible = False
End Sub
Re: [RESOLVED] Column order in DGV
Quote:
Wes, No it isn't bound at design time. Nothing is ever that easy.
No problem but I would still suggest checking out how to manually configure the TableAdapter Fill method, as I described in my previous post. If your going to be using TableAdapters you'll find this skill can be very helpful.
Re: [RESOLVED] Column order in DGV
Wes, Sorry man, I did not read the whole thing. I kind of dropped it at DGV designer, which I use all the time for bound tables. I have never used an SQL to order columns before. I will definitely take a look at that. Thanks.
Re: [RESOLVED] Column order in DGV
It's actually rather simple, you already do (or can) specify the fields in the SELECT clause, and you just put them in the order you want, eg:
Code:
SELECT field1, field8, field3
FROM ...