Combobox inside data-aware cxgrid - delphi

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

Related

How can we hide a particular column in table dynamically based on the value of check box in IBM BPM coach?

In Coach how to hide the column in a brazos tabel control based on check box value check.
when ever check box click in that time i need to show particular column in a tabel, other wise it should be hide.
we are using IBM BPM 8.5.0
Brazos Toolkit
If you click on the Brazos UI Table component -> Configuration -> Hidden columns -> here you can specify a variable. The value for the variable should be integer. So, depending on the value of your checkbox bound variable (true or false) you may control which column would be hidden by assigning corresponding value to the Integer variable that you use in Hidden Column configuration in a Data Table.
Also, keep in mind that the number of the first column is 0.
If you need to specify multiple hidden columns use comma 0,2 for example.
Hope this helps.
Assuming that your checkbox is not a column on your table, I would recommend you wrap your table in a custom coach view, bind a local variable for hidden columns to your table and pass have another config variable variable for the checkbox value. In the load event handler, initialize the values of the comma separated hidden columns variable (this.context.options.<checkBoxVar>.set("value",[value]) based on checkbox value. Within the change event handler, write an event handler (if(event.property == [checkBoxVar])) for the checkbox change and change the value of the hidden columns appropriately.

How to set focus on a particular row in a TDBgrid Delphi

I want to set the focus on a specific row on a Tdbgridview.
First, I choose the criteria field ( column concerned by search ex: FisrtName) from a combo box then I type criteria in a TeditField (ex : Jack ).
Then the arrow of the Dbgrifd should point on the concerned row.
How should I do?
thanks.
The TDBGrid component (and all other TDBxxx components as well) are what Delphi defines as dataware components. This kind of component exists as a visual expression of a dataset.
So, in a TDBGrid you should not think about focusing a row of the grid, rather think about positioning a row of the grid's dataset (using the Locate method suggested by TLama, for instance). The grid will notice that the current row of its dataset has changed (because the grid is aware about the condition of the dataset) and will focus the corresponding row.
Update 1
Below you can see an example of what I said:
MyDataset.Locate('Id', 123, []);
The code above simply looks for a certain record in a dataset named MyDataset. The first parameter is the name of a existing field in the dataset. So, you have a dataset with some fields and one of those is named Id. The second parameter is the value contained in that field in the desired row and the third parameter is some options that do not apply here. Go to the Delphi docwiki for more details on the Locate method.
In other words, we are looking for a row in which the field Id has the value 123! If the dataset can find such a row, it will become the current record (or row). If there is a TDBGrid connected to a TDataSource that is connected to TMyDataset, it will automatically update to select the corresponding row, just like you wanted.

Delphi data aware combo edit control with ability to enter arbitrary text?

I want to enable the user to enter a contact name in an data-aware edit control (combobox, edit) with autosuggest items bound to an sql table.
What I want to achieve is this:
a combo bound to Contact_Name field of a datasource,
an edit bound to Contact_Tel of same datasource
an edit bound to Contact_Email of same datasource
The combo dropdown should be bound to a sql datasource and display person name, phone number and email. The user can pick one of the existing options or type an arbitrary name (new contact person).
When the text of the contact person combobox changes, then
- if the text matches one of existing options, two other edit controls are filled with the phone number and email of the option selected, or
- if the text is not in list, the other two edit controls are cleared.
The set up that I currently have is
a dbLookupComboBoxEh bound to a field of a dataset + a listsource with key and listfields + style = csDropDownEh.
The problem is that it works fine when the user types in a value that is contained in the list source, but once I type in something that is not on the list the control simply gets cleared and doesn't remember the value any more.
Is there a control that combines a data-bound drop down with suggested values AND ability to enter ARBITRARY text?

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;

How to set the default value of a TRxDBLookupCombo control?

Hi all
As the title say. What I want is to make a value as the default value when click a Add button
in the form, the value will be used as a propertity of a document which will be added.
(Yes, this is used in a document management app, one field in the doc will be determined by user via choosing a value in combo, I wanna give user their most possible choice. But now,the default value of combo is empty.)
Just assign the value you want to the field in the dataset which the lookup combobox is attached. The combobox then seek this value in the lookup dataset (the key value) ant show the field value (list value)

Resources