How to display and edit hyperlinks in DBGrid in Delphi 7? - delphi

I use DBGrid to display Hyperlink type field from Microsoft Access database (MDB).
Normally dbgrid displays hyperlink values like "(MEMO)", without editing capablity. Is there a way to solve this?

DBGrid displays values based on field type. If it shows (MEMO) then you probably declared your field in your database as TEXT or something equivalent. Can't remember Access, but in MS-SQL Server you can change field type to varchar and DBGrid will display values as editable text.

Related

Fastreport select fields to print

I have a report where I would like to select which field of database to show/print and hide all unselected field.I had seen in Fastreport demo but its only Choosing records to print. By the way i'm using dbexpress connection and firebird for database.
Any one who has some ideas about this?
Another simple solution would be to solve it on Delphi itself, before calling your Report.
Just add a calculated field to your dataset, and make it return the content of the real field that you want to show on your report. Now you can link your Report to that calculated field, and each time it will present the field that you have selected to present.

Combobox inside data-aware cxgrid

I have a data-aware cxgrid connected to a toracledataset object.
Inside the DB is a column defined as number(1,0) to allow boolean values.
I want to format the corresponding grid column as ComboBox to give the user the ability to choose between the two options.
How can I cast the string inside the combobox to the integer value that will be inserted in the DB?
I know how to do that with a regular combobox, but not inside a cxgrid
The best way will be to use a cxEditrepositiory
add a cxImageComboBox
add Items and define Value and Valuetype
this then can be choosen for your GridColum.RepositoryItem

How to display all data from 2 related tables in a dbgrid with sql

I'm new to delphi and have created an SQL query which displays the results of a search entered by the user through an edit box (showing data from 2 related tables) in a dbGrid.
The dbgrid displays no data until a search has been made and then the results of that search are displayed, however i was wondering whether it was possible to show all the related data in the dbgrid as if it were a table and the search then simply selects from it?
thanks
You could display all the data in the table. Then write an onExit event handler for your edit box which would look something like this (assuming that the string which you are entering in the edit box is supposed to match the value in the 'name' field of the query)
query.locate ('name', edit1.text, [loPartialValue]);
This will cause the dbgrid's cursor to jump to the first line which matches the string in the edit box.
Instead of using the OnExit event, you could also use the OnChange event of the edit box, but this would mean a search after every key stroke.
Your question was a bit vague so it's difficult to give a specific answer.

Delphi grid with a different data type in each row, displayed dynamically

I am trying to create a Delphi grid to allow display and edit in a db grid of data that might have a different data type on each row. I would like to display a specific control for each data type, e.g. when the data type is DateTime, I want to display my custom edit control that allows typing a date in or popping up a calendar.
The data looks something like this:
Name DataType DateValue StringValue BooleanValue
---------------------------------------------------------
A Date 1/1/2007
B String asdf
C Boolean True
...and in the db, this table has a column for each possible type of value. So, there is a BooleanValue column, DateValue, etc.
What I would like to do is display a single 'Value' column in the grid that displays the appropriate edit control depending on what the 'DataType' is for that row. So, the grid should look like :
Name DataType Value
---------------------------
A Date 1/1/2007
B String asdf
C Boolean True
It seems I will need to display a different edit control (to allow the user to edit the Value column) for each row dynamically based on the value of the DataType column. I know there are more advanced grids out there that handle this sort of problem, but the powers that be will not allow anything but what is available out-of-the-box with Delphi.
Any ideas on how to make something like this work?
Personally, I would not go for editing directly inside the TDBGrid in this case, since your Table is not DB normalized (I don't use it in any case actually). I would have used a Calculated field to display the desired value in the grid, And dynamically created the TDBxxxEdits on the form for each field type (How about your own TDBTreeEdit for example, a TDBRichEdit, or a DB Image pickup editor, etc...?).
In case you do want to use your own controls on the TDBGrid, and replace the default TInplaceEdit editor, you can refer the following article: Adding components to a DBGrid, and a related article: Displaying and editing MEMO fiels in Delphi's TDBGrid
Displaying all of the data in the same column is quite easy. You can simply add a calculated string field, and change the value according to what you are storing in that row.
The editing is quite a bit more complicated. If you want to have an in-place editor, you are in for a world of hurt... I've done it, it's a pain, and takes a lot of time. If you want to display a dialog to edit the value, that's much easier. You can add a column objects to the grid and you can setup the column you have attached to the calc field to display a button. When the button is clicked you simply display the editing dialog needed for that row, and commit the edits when the dialog is closed.
There are other ways to get this done, but I would say the above would be the shortest way. Other ways may include custom draw events to display your data in one column, intercept clicks to create your own editor, etc, etc, etc...
after add calculated fields .
Sample:
procedure OnCalculate(DataSet:TDataSet);
begin
case IndexText(DataSet['ValueType'],['Date','String','Boolean']) of
0:DataSet['DateValue']:=StrToDateTime(DataSet['Value']); // also converting
1:DataSet['StringValue']:=DataSet['Value'];
2:DataSet['BooleanValue']:= MatchText(DataSet['Value'],['1','True','T','Y','Yes']);
{etc datatypes}
end;
end;

Setting a DBGrid column format in Delphi

I am using a DBGrid component in Delphi. I wonder how I can set the format of a column. I have real values that I want to be displayed as currency in the grid.
Someone knows how?
You can set the DisplayFormat of the Field
You can handle OnGetText event. This approach allows to do more complex operations with the value.
If you don't add the fields to field Editor list you can get the formating by code as :
TFloatField(MyQuery.fieldByName('MyField').DisplayFormat := '0.00';
if you don't want to show the zeros replace '0.00' with '#.##';
The first port of call is the DisplayFormat of the data field in the database itself.

Resources