I am struggling to assign a style to a TGrid within Delphi Firemonkey. Styling required is quite basic (ie. Align the text in a column and colour per value).
For background, I have created a TGrid, set the rows (eg 200), and added the number of columns (3 in this case). The columns have been labeled as "Code", "Company" and "Balance". As the grid does not contain values (like a TStringGrid), I am able to set the display value via the "GetValue" method (where I retrieve data from an external source). - The result is a list that is fast, and able to cope with a lot of data, the downside is I can not format the design at run time...
I am thinking that I may have to use "Styles"; that are new in FM. If this is the case however, I am not sure how I can reference the cell as it does not really exist as it is painted via the GetValue method when it needs to be drawn?
Any help appreciated,
Regards
Ian.
Ray Konopka's blog might help you here:
http://www.raize.com/Articles/FmxStringGridCellFonts.asp
You can apply a style to a Column by creating the OnApplyStyleLookup event to the column, but to set the font style and color etc you would still need to implement a OnApplyStyleLookup for the TTextCell's themselves too.
I posted a very similar query on Stackoverflow and then found a workable solution which I added here
firemonkey mobile grid with livebindings - changing TextCell text color at runtime XE5
Related
Using Delphi XE7 and FireMonkey I am looking at simple ways of displaying (and editing) some object property values in a TGrid. I have followed the tutorial showing how to bind TGrid columns to object properties and using a TObjectBindSourceAdapter I have a neat, single row grid populated from my one object as they show in the example.
However, I will only ever have one object in the grid (a single row) so I would really like to turn my grid data through 90 degrees to give me two columns - a fixed 'Name' and an editable 'Value'. My object properties would then be listed vertically (effectively like the Object Inspector view).
Is there a LiveBindings way of doing this, or should I use another control such a TListView? I'm new to LiveBindings!
Thanks for any suggestions.
I would like to add an icon to the header of my data grid as it is done in Thunderbird.
There is an icon that is above the vertical scrollbar, no matter the position of the horizontal scrollbar. This icon allows the setup of the columns.
In Delphi there a lot of different grid components, that allow customizations and adding icons to there cells / header cells. But I could not find any component that has an area above the vertical scrollbar that is fixed, which when clicked allows some action. I could even use the VirtualTreeView component to emulate the grid, if it turns out to be easier to customize that component.
I am looking for some guidance on what need to be done to get that functionality.
Thanks,
Thomas
VirtualTreeView in Listbox mode would be nice, because of it's speed, great documentation and ease use in MVC-like patterns. Delphi tempts to store data in the visual components themselves, which letter causes troubles. While VTW allwos the same, it also allows to acutally separate data from GUI, and i like it.
But i am surprised by your claim "which when clicked allows some action.".
Even most basic components allow it:
http://docwiki.embarcadero.com/Libraries/XE2/en/Vcl.Grids.TCustomGrid.OnFixedCellClick
So could you make more detaiils, why you cannot use standard components ? with screenshot and editors, how u want it rendered, where you want to click and what kind of action should happen ?
There seems to be not much information available about this subject so hopefully someone can give some suggestions.
I would like to change color and style of different parts of text in a stringgrid cell.
Example:
20-02-2011 - Document Title
Would it also be possible to show an icon in a stringgrid cell?
It is indeed possible to show icons or bitmaps in a string grid, the Monkey Styler blog includes an example of how to customise cell display in a FMX grid.
http://monkeystyler.com/blog/entry/firemonkey-grid-basics-custom-cells-and-columns
Thinking about the other part of your question though, you will have to build a style up to display text in different fonts, as yet FMX does not have a richtext equivalent or HTML rendering components (I'm sure the latter will come, the former I am not confident on getting for a while!). You would have to have a text component in the style for each different font size/style etc, you would need to name the text elements (using binding or stylename properties) and handle the setting of the text contents using code in the ongetvalue and onsetvalue events (I guess you could also use a onapplystyle event) to display some text in bold and some not.
The event handler would then use either a binding - which is easier to set but - in my experience - buggy;
mycell.binding['boldtext']:='sometext';
Or find a style element by stylename by using findstyleresource;
tempobj:=mycell.findstyleresource('boldtext');
if tempobj is ttext then
ttext(tempobj).text='sometext';
Excuse any bad coding style there, but you get the general idea (I hope) if you set autosize to true for the ttext components in the style and align them left you get - mostly - what you are after. The only issue is that the resulting text doesn't look quite seamless because autosizing and aligning left doesn't really give you the same space between the fonts that you would get with a richtext or HTML display. You should be able to fiddle with the padding (giving it a negative number for the left padding should allow you to remove any extra space) but you have to live with that not being entirely perfect compared to proper font hinting and alignment.
I'm trying to create my first app based on FireMonkey, and I hit a wall.
The only virtual list control I can find is tGrid.
This component is pretty good, but I can not figure out how to extend or customize it.
I get that there is tCheckbox column, tImage column etc, but what if I need a ButtonColumn or something like this?
Also I would like to style a row, based on the state of the data it represents.
An Example: if the data that is represented in the row has "Error=True" it should be displayed in red.
Has anyone got a similar problem? Or found alternate virtual list/grid components? Or even just some tips on use of the tGrid component.
These components are pretty essential in all database apps so it should be a pretty common request.
Also just as a note, I don't think the TGrid supports Drag & Drop of rows?
I have looked at
Firemonkey version of VirtualTreeView
and
Firemonkey and large amounts of data
If you look at the sources, TCheckColumn is only 15 code lines. If you need to create your own column descendant class it's quite straightforward.
This is one solution, otherwise you can dynamically create some components in your cells and then cast the children when checking the props (TColumn.CellControlByRow() return a TControl and the children would be what you have put in there).
As you want to 'style' your row I would suggest you to write your own TColumn class, even if you can do painting in the OnPaint Event.
I have an application, where there are many forms which follow visual form inheritance.
Every form has standard delphi components as well as custom components.
Form validating functionality needs to be added. That is, A small red circle or astric image needs to be drawn next to a control, if the control's value is not valid.
This drawing functionality has to be available through out the application on every control.
What is the best way of implementing this functionality? Is there any design pattern that can help?
Thanks & Regards,
Pavan.
JEDI's JVCL has the TJvValidator component that will do just that for you. Here's a link to the TJvValidators container to get you started.
Something I have done in the past in my validate method was to change the control color to $00C4C4FF for any value which fails validation, or clWindow if it passes. (I use a constant clInvalidEdit). On projects where I am also using Raize controls with a flat border, I also adjust the border to clRed. My required fields generally have a color of $00B0FFFF (again a constant clRequiredEdit).
Most often, I'll create a method named ValidateForm which returns a boolean if the form is valid, or false if its not. The validateform checks every field for validity and adjusts colors where needed, and set the active control to the first field which fails.