locked
DataGridView Not Resizing RRS feed

  • Question

  • I have a DataGridView inside a SplitContainer which is inside another SplitContainer which is in a Form.  The DGV and both SCs have Anchor = all 4 sides and Dock not set.  The DGV has:

    AutoGenerateColumns: true

    AutoSizeColumnsMode: None

    AutoSizeRowsMode: None

    DefaultMaximumSize: {Width = 0 Height = 0}

    DefaultMinimumSize: {Width = 0 Height = 0}

    ScrollBars: Both

    The Form opens Maximized with the SCs (both of which have a visible borders) and DGV properly positioned and sized.  The DGV DataSource is assigned a DataTable which does not fill the DGV horizontally but does vertically.  I programmatically set certain column widths while allowing others to size based on the data in the column.  The vertical scrollbar is showing and the horizontal one is not, both as expected. 

    When I reduce the size of the Form, the SCs resize properly (I can see their borders), but the DGV does not resize.  Instead, it is cut off on the right side, hiding the vertical scrollbar, and has no horizontal scrollbar showing.  Any idea what I'm missing?

    Thanks.  Steve

    Saturday, June 1, 2019 9:45 PM

All replies

  • Hi Cincy Steve,

    In advance, sorry if I misunderstand your situation.

    Do you make DGV .Dock = DockStyle.Fill?
    If not, please try it.

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Sunday, June 2, 2019 4:32 AM
  • Ashidacchi-san -

    Thank you for the suggestion.  I tried it by putting the DataGridView inside a Panel that had Anchor = all 4 sides. The Panel was necessary because the SplitContainer Panel that contains the DataGridView contains other controls as well.  Unfortunately, that didn't fix the problem.  It seemed to behave the same way.  I'm thinking there must be some other property of the DataGridView that's blocking the resizing.  Anyway, thanks for the suggestion.

    I don't know if this is relevant, but I noticed two things:

    1. The DGV's ResizeRedraw property is set to false and Visual Studio indicates I cannot set it.  Apparently that property must be set on the Form (and then inherited by other controls?). I set ResizeRedraw = true on the Form, but that didn't change the DGV's resize behavior.
    2. When I don't Maximize the Form on open, the DGV still doesn't resize when I manually decrease the width of the window. But when I manually increase the width, it looks like the right side border of the DGV gets replicated (redrawn) as I manually move the right border of the Form, with the distance between the replications depending on how fast I expand the window as shown in the image below (the two right-most vertical lines are the borders of the two SplitContainers). Very curious.    

    Steve





    Sunday, June 2, 2019 12:46 PM
  • Hi Cincy Steve,

    Thank you for providing a screenshot.
    But I can hardly know where or which is/are DataGridView,  SplitContainer?  Would you provide a structure of your Windows Form like the below?
        
          (I've drawn this in Excel)

    And I'd like to ask you to provide your code. (Providing a Project would be much better)

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Sunday, June 2, 2019 10:31 PM
  • Ashidacchi-san -

    Here's a somewhat bigger screenshot.  It shows the Form, the nested SplitContainers (each with a solid line border) and the DGVs that are inside the upper and lower panels of the inner SC.  I hope this is now clear.

    I am not able to provide my code which is extensive and I have tried unsuccessfully to replicate the problem in a demo app.  Sorry.

    I have discovered that I can get the DGVs to resize if I reassign the DataSource in a Form ResizeEnd event handler (see code below).   The repeatedly redrawn right border of the DGVs shown in the screenshot are displayed during the manual resize (I'm dragging the right side of the Window/Form), but they then go away after the DataSource is reassigned.  I can stop the right border redraw by putting the DataSource reassignment code in the Form Resize event handler (triggering multiple reassignments if I do the manual resize slowly).  Obviously, I would like to avoid having to do this.

    Steve

    private void Form1_ResizeEnd(object sender, EventArgs e)
    			{
    			DataTable saveSource = (DataTable)dgvData.DataSource;
    			dgvData.DataSource = null;
    			dgvData.DataSource = saveSource;
    			}






    Monday, June 3, 2019 1:52 PM
  • Hi,

    With seeing your screenshots, I can hardly understand which controls are on other/parent controls.
    What looks like bar-code below [Excel Export] button is a DataGridView?
    If so, how many columns are in the DataGridView?
    I hope you will provide a structure (relations between controls) of your Windows Form, and how properties of the columns are described (especially FillWeight, Width and AutoSizeMode of each column).
    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Tuesday, June 4, 2019 3:36 AM
  • Hi Cincy,

    It’s hard to reproduce the problem you’re experiencing based solely on your description.

    As Hokusosha said, the better way to handle the issue is to provide a simple demo that can reproduce the issue.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 4, 2019 5:30 AM
  • Here's a screenshot of the full app window.  I hope this helps identify a way to discover the problem.  The borders on the outside are the SplitContainers. The box under "Search" is a TextBox.  I think every other control should be evident.  As before, I expanded the window by dragging its right edge, which produced the extra right DGV borders.

    Steve


    Tuesday, June 4, 2019 1:36 PM
  • Hi,

    It is impossible to judge the cause of the problem based solely on the pictures you provide. The best way is to reproduce the problem.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 5, 2019 9:47 AM
  • OK.  Thanks anyway to both of you for trying to find the problem.

    Steve

    Wednesday, June 5, 2019 12:29 PM