1

This is a UI issue I have been struggling with for over two days. I am a beginner in WinForms. I have a panel (orange) that is scrollable. Inside the panel is a TableLayoutPanel(gray) with three rows. Each row in the tablePanelLayout is set to autosize. I have a datagridview in each row i.e 3 in total. The datagridviews are not supposed to have any scrollbar (design requirement). Instead, they should display all the rows and push the second datagridview below it and third datagridview below the second with uniform spacing.

The main problem I am having is, the rows in the datagridview ends up fitting inside the container of the datagridview. I do not want them to be contained inside like that, instead take up as much space as it needs. If there are 100 rows, display all 100 rows and have a scrollbar in the main panel and not in the datagridview. This would be easily achievable with gridviews but I am not being able to figure out how to do it in forms.

As shown in the pictures below, if the entire content fits in the form, it will look like first figure, however as you can see in the 2nd figure, if the 1st datagridview is too long, the main panel will show scrollbars and push the 2nd datagridview below it and third one further below. No scrollbars in the datagridview, only the main panel.

Fig 1 Fig 2

Any idea how I can display all rows like that without fitting the rows inside a fixed sized container? There might be a flaw in my understanding/approach so please feel free to direct me to a different route if this is not the way to go. But that is basically what I’m trying to achieve. If something is unclear I can explain that too. Any help would be greatly appreciated.

CodeBreaker
  • 87
  • 2
  • 11
  • 1
    Do you mean you want the Height of the DGVs to depend on the number of rows? (You will have to write code for that) – TaW Jul 15 '19 at 20:17
  • Yes that's exactly what I meant. – CodeBreaker Jul 15 '19 at 20:18
  • 1
    [See here](https://stackoverflow.com/questions/37661303/how-to-fit-datagridview-width-and-height-to-its-content/37662280?r=SearchResults&s=1|53.8023#37662280) - you will have to set the size whenever rows are added or removed. There are two events for that as well as for DataSourceChanged. – TaW Jul 15 '19 at 20:20
  • 1
    Worked! Thanks a lot! – CodeBreaker Jul 15 '19 at 20:53

0 Answers0