Autoresize columns in table to fit Table Width

IoSonoPiero

Active Member
Licensed User
Longtime User
Hello everyone,
you'll find here two short examples on how you can resize columns in a table to fit completely the table width.
The code determine automagically (thanks to Erel, agraham) the if scrollbars are visible and "fix" the widht of columns.

To simply the example,
I'll set the second column dimension to a fixed one.
With simply editing, you can add more columns and do more.

In the first example you'll find a form with a table that has a button under it.
When you press the button, the first column will resize to fit table.

In the second example there is a Timer control that resize automatically the first column to fit table just after the Form is shown on the screen.

Bye,
ghale.
 

Attachments

  • Example_01.zip
    23.4 KB · Views: 420
  • Example_02.zip
    23.2 KB · Views: 368
Door library

Hello.
I don't wanna appear a smarty pants and pardon me being noobish, but it seems to me this can easily be done without any library.:)

Regarding the Door library...could you please give me a reference to get some
knowledge of .Net Framework and the Door library?

Kind regards.
 

Attachments

  • colFit.sbp
    1.1 KB · Views: 278

agraham

Expert
Licensed User
Longtime User
He is using the Door library to pick up the width of the vertical scrollbar to correct the widths so that the horizontal scrollbar is not displayed. Your code does not do this correction and leaves part of the last column obscured by the vertical scrollbar and the horizontal scrollbar still visible.

The ultimate .NET reference is .NET Development. It is probably best to use ".NET Framework 2.0" as your reference. Methods and properties available in the Compact Framework have a little device icon by them as shown here TextBox Members (System.Windows.Forms)

Most of the UI stuff is in System.Windows.Forms, you get to that example by selecting the following in turn in the left hand pane.

.NET Development
.NET Framework 2.0
Class Library Reference
System.Windows.Forms
TextBox Class
TextBox members
 
Last edited:
Hellow Andrew.

Writing my code I was just lazy to subtract 10 from each final column width value so that the vertical scrolbar is not displayed.

Begarding the second column being obscured by the vertical scrollbar....it's partially obscured in Ghales table whereas in mine both columns' widths are visually equal(when the Hscrollbar is not displayed)
After all who am I to argue with you? :sign0089:

Thank you for references, hope I'll be able to sort that stuff out from scratch.

Kind regards.
 
Top