dbgrid autofit to a form - delphi

I have used DBGrid in BDS 2006.It has 6 columns which are populated during runtime.
The datatype for for one column is char(150) in mysql database. since while retriving from database to dbgrid it takes the length and the columns become wider with a scroll bar and some coloumns remain hidden.
so my question is how to fit these coloumns of the dbgrid to the form?

You can use the free JVCL JEDI Visual Component Library
Use the TJvDBGrid and set AutoSizeColumn to True. It will all allow the columns to fit for the DBGrid width and show no horizontal scroll bar.

Related

Vaadin Grid: setAutoWidth(true) with recalculateColumnWidths() works only for visible rows in the grid

After I setup the a Grid with all the columns with setAutoWidth(true) and I execute grid.recalculateColumnWidths() this will auto-adapt the columns width with the content of the columns but only for the rows that are visible in the grid.
What happen is that scrolling rows in the grid I can find some cells with content larger than the content on the first visible rows and they were not auto-adapted and so the content is truncated (es FOO...)
Considering that I am using ListDataProvider, so all the rows are loaded into memory when I build the grid, why it is not calculating the right width for every column considering all the rows?
Is this a normal behaviour? It is possible to change it to consider all the rows when it is calculating the columns width?
I am using Vaadin version 14.
Thanks for the help
Yes,
this is the normal behaviour of the vaadin grid and is (at least for the 23.x) documented that way
https://vaadin.com/api/platform/23.2.6/com/vaadin/flow/component/grid/Grid.Column.html#setAutoWidth(boolean)
The relevant part, why it's not looking at all items in the grid is here:
For performance reasons the column width is calculated automatically only once when the grid items are rendered for the first time and the calculation only considers the rows which are currently rendered in DOM (a bit more than what is currently visible). If the grid is scrolled, or the cell content changes, the column width might not match the contents anymore.
You can however "retrigger" a width calculation
You can manually trigger the auto sizing behavior again by calling Grid.recalculateColumnWidths().

How to fix a column in TStringGrid with delphi FMX?

I want to make a grid with FireMonkey where it has a fixed column, but neither TGrid nor TStringGrid have that property, nor allow me to change it dynamically at runtime, as far as I can see.
Does anyone have a way to make this work?
Imagine I have 500 columns (I don't, and I won't have that number, this is just for demonstration purposes). I want to lock the first column so its content will always be visible as the user scrolls the grid along the X axis (horizontally). Same thing as with the header row, it's always locked in place so when the user scrolls along the Y axis, the header is always visible.
I am using Delphi 10.3.3 CE.

Freeze Columns in Vaadin 7 table

I have 20 columns in a vaadin 7 table, I want to freeze 4 columns so that whenever we scroll horizontally we should be able to see those frozen columns always.
There is no freeze columns feature in Vaadin 7 Table. But in newer Grid component you can set the X left most columns to be frozen with Grid.setFrozenColumnCount(..) methdod, see more here:
https://vaadin.com/api/framework/7.7.14/com/vaadin/ui/Grid.html#setFrozenColumnCount-int-
If you want to do something similar with Vaadin 7 Table, you probably need to do the following
Use two tables with the same data source Container
Wrap them inside e.g. CssLayout
Give z-index to other Table so that it is placed on top of the other in your theme CSS styles (Table.addStyleName("frozen-columns-table"))
Set the Table on top have only the "frozen" columns with setVisibleColumns(..) method
Set/style column widths etc. accordingly. The Table on top needs to be narrower than the bottom Table.
The above approach has its limitations and performance impacts, but could be a solution in some cases.

How To Scroll a TStringGrid dynamically?

I am working in the Borland C++Builder IDE, using VCL controls. I am trying to get a TStringGrid component to scroll down to a row and highlight that row, based on user input in a different form. I have the highlight portion done, but I can't figure out how to scroll the grid down to the correct row. Anyone here know?
Set the TopRow property.

Delphi - How to set vertical scrollbar in TStringGrid, always visible

I'm using Delphi 2007 for Win32 and need to set the vertical scrollbar in TstringGrid to always be visible. How do you do that?
You can hide scrollbars with the Scrollbar property set to either ssNone, ssHorizontal, ssVertical, even when the number of rows and / or columns would normally make them appear.
You can however not force one or both scrollbars to be always visible but disabled, without creating a new descendent class and overriding methods. Unfortunately the standard grid controls have not evolved much since the days of Delphi 1, so your best bet is using some third party grid control instead. Preferably one that does also show proper proportional scroll thumbs.
There is a scrollbar property that can be set to ssNone, ssHorizontal, ssVertical or ssBoth.

Resources