How to fix a column in TStringGrid with delphi FMX? - delphi

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.

Related

Move Grid save and cancel buttons from far right, maybe left justify

Is there a way in Vaadin 7 or Vaadin 8 to move the save/cancel buttons to under the last editor column? Or maybe to left justify them? Right now they are right justified under the last column. I would even take left justifying them under this same column. Visually, it is far from the last thing the users edited, so some users get confused. The way I am clarifying it for users right now is by making the Grid as narrow as possible, but it wastes screen real estate.
This will be very difficult in generic case, where column widths can be freely adjusted or their widths are automatically calculated by content. However if you set your columns fixed widths, so that you can make assumptions based on that within your specific application, there is a solution.
Just noting, that the Editor has div, with class name "v-grid-editor-footer", which has the same width as the Grid. So the editor footer does not have logical cells, that would be aligned with Grid's cells. And that is the challenge here. Furthermore the buttons you are refering to are wrapped in a child div of the previous one, with class name "v-grid-editor-buttons"
However you can try to add css rules in your theme in the following way.
.v-grid-editor-buttons {
position: relative;
left: -300px; // Adjust this value experimentally so that it fits your need
}
Below is a screenshot the css applied to Vaadin's Sampler.

Smooth scroll string grid

I need a string grid which can scroll smoothly, as opposed to locking in the top row / left col positions. When you scroll a TStringGrid, the left visible column and top visible row snap into position along the top/left edges. I need the ability for the user to scroll smoothly, not locking these edges into place.
I wouldn't think this is possible to modify in the VCL TStringGrid (or TCustomGrid for that matter) because it relies on properties such as TopRow, LeftCol, VisibleRowCount, etc.. I'm pretty sure I'll need a third party control, but I'd love to use the TStringGrid if possible, because I already have a lot of code wrapped around it. If I do need a third-party grid, then I'm hoping it works closely enough like the TStringGrid.
The short answer is no, you canĀ“t pixel scroll a TStringGrid. You can simulate a grid using a TScrollBox. You can put a grid inside the TScrollBox, make the grid large enough to fit all rows and cols, and turn off its scroll bars, but some things like keyboard navigation will not work.
Other alternative is to use the TVirtualTree in grid mode or TListView. Both have this pixel scroll you want.
I was looking for something similar. Unfortunately, you can't do it with Borland's code but Lazarus can do it
Scrolling the TStringGrid pixel by pixel
You may want to take a look in their code.

dbgrid autofit to a form

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.

Delphi - How do I fix this strange TGrid behaviour?

Delphi 2007.
I have a TGrid with more rows than will fit on the screen, and the height of the grid is such that there is a partially drawn row at the bottom.
When I click on this partial row, it jumps up to be fully visible (via a procedure called 'ClampInView' in Grids.pas). But it doesn't stop. Since the mouse is now over a new partially drawn row, that jumps up too.
The net effect is that clicking on the partially drawn row starts selecting cells in a vertical column, spinning all the way to the bottom (or until you release the mouse).
I have replicated this on a fresh winforms project with just a single grid with 100 rows, and no code, so I'm pretty sure it's not something I'm doing in code wrong.
It is bad for me because the form I have in real code has drag and drop type behaviour, so clicking and releasing ~0.1 seconds later on the partial row will pick up the item in the cell and drop it about 50 rows lower. This is definitely not what you expect to happen when you click on a cell.
Any suggestions how to fix/work around this?
This is what I have always done because I think it is tacky to have partially visible rows. I adjust the size of the grid so its client area is an even multiple of row height. You can do that at design time, or it is easy to do via code as well. The kicker would be if you have re-sizable rows. If that is the case then just put the code to resize the grid in the event handler for the row resize event (I believe it has one).
Not only does this prevent the behavior you are trying to fix, but it also (in my opinion) makes your UI look a lot cleaner!
You can try override MouseDown in your grid and do not call inherited MouseDown, if user clicks in "bad" places.

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