Results 1 to 4 of 4

Thread: DataGridView AutoSizeColumnsMode Fill Problem

  1. #1

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    DataGridView AutoSizeColumnsMode Fill Problem

    Hi

    I'm having a problem when trying to add a column to a datagridview in autosizecolumnsmode set to fill.

    After some tests i realize that i can't insert a column to the datagridview. The autosizecolumnsmode it's set at design time.

    vb.net Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim sqlCon As New SqlConnection("******")
    3.         Dim sqlPFs As New SqlCommand("spTest", sqlCon)
    4.         Dim adapterPFs As New SqlDataAdapter(sqlPFs)
    5.         Dim dtPFs As New DataTable
    6.         Dim bs As New BindingSource
    7.  
    8.         sqlPFs.CommandType = CommandType.StoredProcedure
    9.         adapterPFs.Fill(dtPFs)
    10.         bs.DataSource = dtPFs
    11.         DataGridView1.DataSource = bs
    12.  
    13.         If DataGridView1.Columns("Info") Is Nothing Then
    14.             Dim colInfo As New DataGridViewImageColumn
    15.             With colInfo
    16.                 .Visible = True
    17.                 .Name = "Info"
    18.                 .Frozen = True
    19.                 .ImageLayout = DataGridViewImageCellLayout.Zoom
    20.                 .FillWeight = 50
    21.             End With
    22.             DataGridView1.Columns.Insert(0, colInfo) ////////////WHEN SET TO FILL IT JUMPS OUT HERE
    23.         Else
    24.             DataGridView1.Columns("Info").Visible = True
    25.         End If
    26.     End Sub

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: DataGridView AutoSizeColumnsMode Fill Problem

    I haven't tried this, but i'd turn off autosizecolumnsmode, insert a column, then turn autosizecolumnsmode back on...

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: DataGridView AutoSizeColumnsMode Fill Problem

    I've just noticed your dgv is bound. did you try inserting the column into the datatable?

  4. #4

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: DataGridView AutoSizeColumnsMode Fill Problem

    I already tried some combinations:

    1 - Design to NONE, in the end of the code changed to FILL, columns doesn't adapt at all...
    2 - Design to FILL, before adding the column set to NONE, after finishing set to FILL, the columns in the datatable fill the space but the new column doesn't... scrollbar visible.
    3 - Design to FILL, before adding the column set to NONE, in the column changed the AutoSizeMode to fill, when the code reaches the addding part it jumps out...

    By adding the columns to the datatable directly, should work.

    But sometimes by some reason the columns must be added directly to the datagridview without messing with the datatable... and in those situations why we can't add columns when set the auto size columns mode to fill.
    Some kind of issue with this combination? Datatable + Fill + Add Column?

    Thanks

    Rate People That Helped You
    Mark Thread Resolved When Resolved

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