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

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?

Related

How to load pictures from a list asyncron, to show the text first

I want to load a list with thumbnail pictures from the internet. In order to have a good user experiance, I want to load and display the text of the list first, and want to load the pictures from the list in a background thread. When a picture is downloaded I want to show it in (refresh) the correspondig row of the list.
Actually, I don't know where to start. Can I use a TClientDataset component to load the text first and load the pictures in a background thread and insert it with .Locate() .Edit .Post to the dataset?
You can use a TClientDataSet for requesting the data directly, except the picture. Thus, the fetching of the main data should be fast enough.
You should load the picture as a calculated field then. Documentation says (with my own emphasis):
A calculated field displays values calculated at runtime by a
dataset's OnCalcFields event handler. For example, you might create a
string field that displays concatenated values from other fields.
To create a calculated field in the New Field dialog box
Enter a name for the calculated field in the Name edit box. Do not enter the name of an existing field.
Choose a data type for the field from the Type combo box.
Enter the size of the field in the Size edit box, if appropriate. Size is only relevant for fields of type TStringField, TBytesField, and TVarBytesField.
Select Calculated or InternalCalc in the Field type radio group. InternalCalc is only available if you are working with a client dataset. The significant difference between these types of calculated fields is that the values calculated for an InternalCalc field are stored and retrieved as part of the client dataset's data.
Choose OK. The newly defined calculated field is automatically added to the end of the list of persistent fields in the Field editor list box, and the component declaration is automatically added to the form's or data module's type declaration.
Place code that calculates values for the field in the OnCalcFields event handler for the dataset. For more information about writing code to calculate field values, see Programming a calculated field.
In OnCalcFields event handler you then need to implement asynchron loading of the picture.

How to bind list of TextField to binder(FieldGroup or BeanFieldGroup)?

I have requirement like following.
In page for Employee record entree there are 3 types of field Name, Phone Numbers and Address. User can enter 1 name and 1 address per employee but he can add multiple phone numbers by using multiple text field.
Initially there will be only 1 text field for phone number but user can add more text field using button. So text fields for phone numbers can increase and decrease.
For this requirement it was easy to bind name and address, since there will only 1 entry. But for phone numbers I have to use list and I am unable to bind list of text fields to list of strings.
you have to write a CustomField<List<String>> for this. Implement the abstract methods and then override (get|set)InternalValue read and spread the values into list of textfields (e.g. on set remove all textfields, add one for each item in the list and add an additional one for new ones and some add-button). then you can use this field to bind to your list.

How can I auto-fill Edit fields by using different options of a drop-down list?

am using a VCL form in Delphi, where I have put about 10 edit boxes.
These Edit boxes contain values that are related to specific models of solar panels.
These values are needed in order to calculate the output power of a solar panel.
So far, I am able to type these values in every run with the command:
c0:= StrToFloat(Edit1.Text);
for c0 to c10. But, instead of asking the user to manually type these 10 values in each run, is there any way to let the user select one option (i.e. a model of a solar panel) of a drop down list and these values being filled automatically for them?
Does the combobox do such a thing and if yes, how exactly? I am sorry, I am a very new Delphi user. Any help much appreciated.
Set the combo box Style to csDropDownList.
Populate the combo box Items with appropriate values for the user to select.
Add an OnSelect event handler. This will fire whenever the user selects a new item in the combo box.
Implement the OnSelect event handler by populating the edit controls with appropriate values, based on the value of ItemIndex.
You will need to think a little about the UI. If the user changes the combo box selection, then the edit control values change. But can the user then modify the edit controls? Now the values in the edit controls no longer match the combo box. Is that what you want? I guess that the UI needs a little more polish.

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;

Why would a SharePoint lookup menu require a double-click to select an item?

I have a SharePoint feature which programatically creates 3 lookups in a custom list, one from each of 3 different lists via extremely similar CAML markup.
The only differences in the CAML are the List, ID, Name, DisplayName and StaticName properties yet one of these lookups looks slightly different (has a slightly more "modern" drop-down arrow) than the other two and this same menu requires I double-click in order to select an item instead of single-clicking as I do with the other lookups.
Might anyone have seen this before and have an idea of what I might look into to make this lookup operate as a single-click menu?
The style of dropdown displayed is usually related to the number of items, although it also renders as a standard select element when viewed in firefox.
For any other field type it would make sense to create a custom field control, but due to code that expects things to be named "Lookup", lookup fields are next to impossible to extend.
The best way to customize a specific field is probably with javascript/jquery. When you click on the dropdown arrow, ShowDropdown (in core.js) is called. This creates a select element with options set from the pipe delimited list in the choices attribute of the textbox.
Add some code to the page so that on load EnsureSelect and FilterChoice or similar are called to create the select element. Set properties on the textbox and select elements so that the textbox as hidden and the select element is a visible dropdown. Have SetCtrlFromOpt called on change rather than on blur/double click so that the control that the server will read and save is properly updated.
The same approach could be used to keep the combo box but add a click event to set the value rather than requiring a double click.
How many items has the source list of every lookup field?
Lookup fields shows a "Combo" when the source list has 10 items (I'm not sure if 10 item is the exact limit). When the source list has more than 10 items the lookup field shows a "ListArea" control that works as you said.
I have exactly the same problem. One difference I have noticed is that the one listbox that requires a double-click is a lookup field, whereas the one that doesn't is a choice field with pre-populated choices. Don't know if that helps.

Resources