Results 1 to 2 of 2

Thread: Vb.net cannot change Datagridview column index

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2016
    Location
    South Africa
    Posts
    141

    Vb.net cannot change Datagridview column index

    I am trying to increase the width of a last dummy column in a datagridview so that I display certain rows after a button click.
    The DGV is bigger that the screen so it scrolls, also the forth column is frozen.

    I am using the following code :
    Code:
    Private Sub ButtonHierdieWeek_Click(sender As Object, e As EventArgs) Handles ButtonHierdieWeek.Click
            Dim BufferKolomWydte As Integer = 0
            For i As Integer = 23 To 32 Step 1
                SkeduleringDataGridView.Columns(i).Visible = False
                BufferKolomWydte = BufferKolomWydte + SkeduleringDataGridView.Columns(i).Width
    
            Next
            BufferKolomWydte = BufferKolomWydte + SkeduleringDataGridView.Columns(12).Width + SkeduleringDataGridView.Columns(13).Width
    
    
            SkeduleringDataGridView.FirstDisplayedScrollingColumnIndex = 15
            SkeduleringDataGridView.Columns(33).AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet
            SkeduleringDataGridView.Columns(33).Width = BufferKolomWydte
    
    End Sub
    However the column width does not change. I have set the DataGridViewAutoSizeColumnMode to NotSet above.
    Is there another setting that I am missing?

  2. #2
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Re: Vb.net cannot change Datagridview column index

    Hi Gideon,

    This might help.

    You might like to note that
    Code:
     For i As Integer = 23 To 32 Step 1
    can be written as
    Code:
     For i = 23 To 32
    The index will always be an integer and the step is 1 by default so is only needed if the step is to be something other than 1, (-1, 2, 5 etc.)

    Poppa
    Last edited by Poppa Mintin; Mar 9th, 2023 at 05:34 AM.
    Along with the sunshine there has to be a little rain sometime.

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