I'm trying to bind a INTEGER table field to the ITEMINDEX of a combobox.
The combobox have your items predefined at design time.
If I bind the SelectedValue with the Table field, the String related to the item, not your index, are passed, resulting in "not a integer value" exeception.
If I bind to the ItemIndex value, the link is UNIDIRECTIONAL, and I want a bidirectional bind.
There are a way of doing such binding?
i dont understand your problem but i can give ideas as i understand.Pls picture it nexttime. First,if you want to add FruitDB.datas to combobox use formattext or
//select x from fruit order by fruitid asc
cb>style= dropdownlist and CB>add(Trim(fruitname)+space(5)+inttostr(Fruitid));
(apple 1
pear 11
apricot 12)
create 2 function return string and integer
seek for first space to i integer i=posstr(' ',cmb.item[x]) and
fruitname = copy(cmb.item[x],i,0) and fruitid= copy(reversestr(cmb.item[x]),Length(cmb.item[x])-(length(fruitname)+5),0)
and create 1 function again for indexof items return integer like
seekincmb(fruitnm:string):integer
for id= 0 to iemcount -1do if fruitname(cmb.item[id]) = fruitnm then result:= id break;or if you need fruitid ,you can add it too.
you call them in cmbOnchange or OndrawItem or where you want.
if you wont search on combo,use cmb.drawitem and fruitname function for display item
if you want search on combo,put an editbox on combobox and fix edge, editonchange or keypress or keyup,seek cmb.itemindex:= seekincmb( edittext);
Related
I want to limit the check box selection of selectItem in smartGWT. My select item contains "n" number of options but the user wants to select only maximum of 7 options from the selectItem. How can i achieve this?
You can choose from several ways to achieve this.
I would choose between these two options (depending on your application):
Add a CustomValidator to that Formitem. This validator should evaluate to false if the SelectItem contains as value a list with more than 7 elements. Note that such a Validator could transform the value of the item and that you could specify the error message next to the formitem.
Add a ChangeHandler (via addChangeHandler) to the FormItem and chancel ChangeEvents when more than 7 elements are selected (and provide a notification to the user).
I have a field (OK) in my cxGrid which is displayed as a checkbox (properties : checkbox). It is an actual database field (boolean) in my SQLite database . Can I group this field so that the grid displays how many items are checked and how many are not (default for groups) ? Right now I managed only to count the items.
The display I have now is something like this :
I need to count checked and unchecked items. Is this possible at all?
EDIT :
In one similar program I have such a feature implemented below) :
Here the sum works since it sums up numbers. In this case I dont know how to sum up
true/false thing... The best next thing I came up in this example is this :
Just changed the field name from 'ok' to' urejeno' ....
I have a table called Artist which currently contains four records and a TSQLQuery that contains the following statement:
SELECT name
FROM Artist
The table Artist also contains the following records:
id name
1 Artist 1
2 Artist 2
3 Artist 3
4 Artist 4
Current method of record retrieval:
Query1.Open;
for i := 0 to qArtist.FieldCount -1 do
with cbArtist.ListBox.ListItems[i] do
Text := qArtist.Fields[i].AsString;
Previous method of record retrieval:
Data bind Query1 to ComboBox1.
With the "previous" method, ComboBox1 would display all the expected records from the Artist table. However, when I try to use "current" method Query1 is only selecting the very first record from the Artist table despite there being three other existing values. I have tried the "current" method across other queries and they also returned only the first value of the table.
The reason I am going for this new approach is because I feel that I am very limited in what I can do if I continue to the "previous" / data bind method, but that is besides the point.
So how can I fix this problem? i.e. the problem of the query only selecting the very first record from the table.
You must use the Eof and Next methods to iterate over the records.
Query1.Open;
while not Query1.eof do
begin
cbArtist.Items.Add(Query1.FieldByName('Artist').AsString);
Query1.Next;
end;
You code show an interaction over fields, if you need iterate all record then you must use a code like:
Query1.Open;
Query1.first;
while not Query1.eof do
begin
with cbArtist.ListBox.ListItems[i] do
Text := qArtist.Fields[1].AsString; //put here field you want to bind on ListBox.
Query1.next;
end;
I don't think you are navigating your query's dataset correctly. The FieldCount and Fields[i] access the field metadata (columns going across), not the rows. I beleive in Delphi you use While not Eof begin... end.
Navigating Datasets
I would consider altering the data binding fields to suit your needs. Delphi's Databinding is very powerful. Manually iterating the dataset just to populate a control will just be extra code where bugs can hide. Utilize the built-in capabilities of the tools and it will be easier to understand and maintain.
I have a DevExpress TcxDBLookupComboBox v12.1.5 with:
DataBinding.Datafile -> integer field
DataBinding.DataSource -> dbisam table
DropDownListStyle -> lsEditList
ImmediatePost -> true
ListFieldIndex -> 1
ListFieldNames -> itemcode; itemname
Item Code is a integer field, that I want to be retrieved to the connected dataset. However I want to search on the drop down list by the item's name
That is working, due the ListFieldINdex, however when I select the item on the drop down list it retrieve the itemcode and display the itemname on the edit box. That is not what I need.
I know I can change the DisplayValue using the OnValidate Event of the component, however I cant find how to retrieve the selected itemcode from the dropdownlist. Using the connected dataset field always return 0. ImmediatePost is not changing anything on the field. I am retrieving fields from the dataset using the FieldByName property.
How can i get the itemcode seleted to pass to the DisplayValue on the OnValidate?
Is there a better way to do this?
UPDATE:
I am now using the SyncMode, and by that I can easily get the itemcode from the record selected.
However I could not make the control work the way I need:
to enter the itemcode directly for direct access
to open the lookup for itemname search
display the ItemCode when the I find the search by itemname and the lookup list get closed
I have a column in a DB table which stores pressure. The pressure is always stored as PSI and can be converted to BAR by diving by 14.5.
The user can toggle display of PSI/BAR with a Radio Group.
I was using a TStringGrid and am converting to a TDbGrid - which is quite new to me.
When the user toggles PSI/BAR, how to I update the display in my DB grid? (I imagine that I just execute it's query again? or Call query.Refresh()?) But how do I do the conversion?
Possibly a stored procedure, although that seems like overkill and stored procedurs are also new to me...
By changing the SELECT statement of my query? But how would I do that? SELECT pressure / 14.5 FROM measurements? Or how?
Or is there an OnBeforeXXX() which I can code? Or OnGetDisplayText() or some such?
I am sure thta this is very basic, but until now I have just been displaying unmanipulated data and now I need a conversion function. Google didn'ty help, but I probably didn't know what to ask for.
I also want to change the text of the column title, toggling between "Presure (PSI)" and "pressure (BAR)".
Thanks in advance for any help.
Code a OnGetText event handler for the pressure field like this:
type
TPressureMU = (pmuPSI, pmuBAR);
const
PSIToBarFactor = 1/14.5;
procedure TdmData.qMeasurementsPressureGetText(Sender: TField; var Text: string;
DisplayText: Boolean);
begin
case PressureMU of
pmuPSI: Text := FloatToStr(Sender.AsFloat); //Already PSI
pmuBAR: Text := FloatToStr(Sender.AsFloat * PSIToBarFactor); //ConvertingToBAR
end
end;
I'm using a property PressureMU of the declared enumeration to control if the pressure is shown in PSI or BAR measurement unit.
This way, when the user changes the selection, you just adjust the value of that property.
If you use persistent fields, you can link the event handler directly to you field using the object inspector, and if not, you can do it by code like this:
begin
qMeasurements.FieldByName('Pressure').OnGetText := qMeasurementsPressureGetText;
end;
where qMeasurementsPressureGetText is the name of the method.
Create persistent fields (right-click the query, and choose Add Fields to create fields at design time that are stored in the .dfm). Right-click the query, and add a new field. Make it a calculated field, and in the OnCalcFields event of the query do the conversion from PSI to BAR.
Now when the user toggles the display, you just display either the PSI or BAR column by setting the Column.FieldName, setting it to the actual PSI column or tne newly calculated BAR column.
Of course, if you're not using persistent fields, you can do it all in the query. Simply add a new column in your SQL statement that contains the result of the conversion, and you can still just change the Column.FieldName at runtime to toggle which value is being displayed.