The TDrawGrid component has a standard way of determining how much to scroll when you scroll to the right and left for example. I want the same behaviour as with a TScrollBox. The amount scrolled to the right and left is a lot less and you can control that. I was using a TScrollBox for this exact reason until I figured out that I can't have fixed Rows and Fixed Cols anymore because my ScrollBox determines the scrolling.
Is there a short way to do this without creating my own component?
Related
Searched all over Google and I'm afraid I can't find an answer to this.
Here is my current situation:
Instead of having those checkbox aligned to the left I want them centered like so (photoshopped obviously):
Anybody know how to achieve this with VCL? Thanks.
Edit:
These components are inside a TGridPanel and for whatever reason the Left and Top properties have no effect on the position of the component in the cell. I have also looked for any layout properties with no luck.
The controls inside the TGridPanel are automatically center-aligned. If you reduce the width of the checkboxes to the correct value it should be centered as requested. Be aware that if you reduce the size too much the checkbox will shrink.
I managed to find a solution although it's rather messy. But for future reference I had to create a panel for every single cell in my GridPanel then that allowed me to set the left padding property of the panel to push my TCheckboxes over.
Yes it's super inefficient but it's the best I've got so far. Also fixes my issue of wanting to show the cell outlines inside the GridPanel.
I have a THorzScrollBox in a form, and some TStyledControls inside. Each StyledControl has a Tag to identify. Using an TEdit to inform a value, I can find inside the ScrollBox an specific Control by his tag.
If the control that I searched is not on the screen, I want to scroll the ScrollBox to show it.
How can I do this programmatically?
I found a way to do this.
I have to use ScrollBy. But the detail is that if I want to scroll the controls to right I have to use a negative value.
Example:
sbItems.ScrollBy(-10, 0); // this will scroll to right
If I use a positive value, it will scroll to left.
sbItems.ScrollBy(10, 0); // this will scroll to left
The point is, if you scroll once, the ViewportPosition will change and the next time you execute ScrollBy, it will not reset the scroll position, it will scroll from the point you already have scrolled.
I see lots of DB scroll bar questions, but never seem to find a definitive answer to this one.
There is no option (property) to add/hide DB grid scroll bars, either singly or jointly. The simply auto-appear when needed.
If I don't have enough rows to scroll, I would like my columns to fill the entire grid.
If I design it so then when a vertical scroll bar is added at run-time a horizontal scrollbar is auto-added too (since I just covered the right part of the right most column with a vertical scroll bar, we now need a horizontal scroll bar to see what I am covering).
One option is to design my grid such that there is enough space at the right hand size (how many pixels?) to accommodate a vertical scroll, but that is unsightly until there are enough rows to trigger a scroll bar (if ever).
It seems to me that the most aesthetically pleasing way would be start with a grid which is filled with columns at X pixels wide and increase its width to X + width of vertical scroll bar (or decrease the width of one/some of the grids columns by a total of width of vertical scroll bar) pixels when adding a new row causes the vertical scrollbar to appear.
Am I missing something? Is there a “correct” way to do this, or an industry standard way (I am not asking for a “best” way or anything too subjective, so please don’t close. I believe that a lot of people need to know this).
Is there anything in the standard TDBgrid to facilitate this?
Bonus: I subscribe to TMS components, so if there is a way to do this simply with TAdvDbgrid, that would be fine for me, but a general solution with TDBgrid would be fine.
Non-subjective question: Given that
- I do not want to increase the width of my TDBgrid
- and that I do not want a blank white column at the right when no vertical scroll bar is present
- and that I am willing to decrease the width of my right-most column in order to avoid a horizontal scroll bar appearing when a vertical scroll bar appears
... how do I do so?
[Update]
Ken was rightly awarded the answer becuse his solution is best for most users.
For those like me who already paid for a TMS subscription, I just noticed that their TDbAdvgrid component has a ScrollBars property and when I set it to ssVertical, it does what I want.
Now, if I could only figure out a good way to have fixed header row when it is the only row ...
TJvDBGrid (part of the JEDI JVCL) has this capability built in, and includes source code. It should be able to either do what you need, or give you the details needed to implement your own descendant.
I am using the VirtualTreeView together with the OnMeasureItem event to display rows of variable size. The problem is that the event seems to be called only if a row is painted (following the virtual paradigm). But this leads to the scrollbar being displayed incorrectly. If I scroll to the bottom (by dragging the scrollbox with the mouse, not clicking the scroll buttons at the top or bottom), not the last row is displayed (which is what I would expect), but some row in the middle. After that, the scrollbar is updated and I can scroll further down. It seems as if the component uses the DefaultNodeHeight for its scrolling calculations. But since my rows have variable height, I cannot specify a DefaultNodeHeight that would lead to correct results. Option toVariableNodeHeight is enabled.
Has anyone experienced this before and maybe found a workaround? Or am I doing it wrong?
You need to set DefaultNodeHeight to the maximum value you will be using and OnMeasureItem event set custom height value for the current node. Similar issue was described here.
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.