Results 1 to 7 of 7

Thread: [RESOLVED] Column order in DGV

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Resolved [RESOLVED] Column order in DGV

    I have the following form:

    Name:  DGV.jpg
Views: 319
Size:  86.7 KB

    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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Column order in DGV

    Try this:
    Code:
    dgvList.Columns(19).DisplayIndex = 1

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,508

    Re: Column order in DGV

    Also, if your DGV is bound at design time then you can use the DGV designer to arrange the columns. Also, you can open the dataset in the IDE and EDIT the TableAdapter SQL statement. Just right click on the tableadapter method you want to change and then select Configure. You can retrieve the ccolumns in any order you want.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Re: Column order in DGV

    Wes, No it isn't bound at design time. Nothing is ever that easy.

    Geek, Thanks, that works perfectly. Now that I see it, I probably should have been able to figure that out. But then that can be said for almost anything. It always looks simple after the fact.

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,508

    Re: [RESOLVED] Column order in DGV

    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.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    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.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width