Radstudio ListView and FireDac Binding Synch Issue - delphi

I have a table with a primary key (ID) and a unique field (REF) that I want to bind to a ListView.
With LiveBindings the links are created with :
1) (Table) * <-> Synch (ListView)
2) (Table) ref -> Item.Text (ListView)
Additionaly, a link are created with other component:
3) (Table) ref -> Text (ListBoxItem1)
ALL WORKS FINE if IndexFieldNames of Table are ID.
But I want to sort records by REF and when I set IndexFieldNames = ref the selected table record is always the PREVIOUS selected item on ListView, this means:
At same time that the selected ListView.Item.Text = "Ref of Record no. 2" the ListBoxItem1.Text = "Ref of Record no. 1".
I'm new with live bindings, did I make some mistake?

Before set IndexFieldNames, You need call the procedure ResetNeeded of TBindSourceDB component

I only get a workaround:
1) Do NOT connect synch of listview;
2) IndexFieldNames = ref
3) Inside event OnClick (ListView) use a Table.Locate to set the correct clicked record.

Related

Vaadin Combobox does not shows nameField from database

I have a service class. When I set items alldata() in my combo box then it shows all the embedded data from the database. how can I just set the name field?
example:
private ComboBox groundComboBox = new ComboBox<>("Ground");
groundComboBox.setItems(groundService.getAllGround());
it shows:
Ground(groundId=Shere-Bangla, groundName=Shere-Bangla national stadium, city=Dhaka, country=Bangladesh, longitude=90.8, latitude=45.7, capacity=10000, inaugurationDate=2005-02-05).
i just want to show the only name;
You need to set the label generator to define what will be the label of each item.
groundComboBox.setItemLabelGenerator(Ground::getName);
or
groundComboBox.setItemLabelGenerator(ground -> ground.getName());

VB6 populate a list box using adodb recordset

I had a form which originally used Listview control but I need to change it into Listbox control. Now here's the original code which use for listview. I'm trying to change it for populate listbox using adodb recordset but keep getting errors. lv1 is the listbox1; lv2 is the listbox2. Listbox doesn't have listitem.
Private Sub PopulateListView()
Dim cnPop As ADODB.Connection
Dim rsPop As ADODB.Recordset
Dim lst As ListItem
Dim lngRecs As Long
On Error GoTo ErrPopulate
Set cnPop = New ADODB.Connection
cnPop.CursorLocation = adUseClient
cnPop.Open gcnORA
Set rsPop = New ADODB.Recordset
rsPop.Open sSQL, cnPop, adOpenDynamic, adLockReadOnly
lv1.ListItems.Clear
Do While rsPop.EOF = False
Set lst = lv1.ListItems.Add(, , rsPop!Customer_Number)
lst.SubItems(1) = rsPop!Customer_Name
rsPop.MoveNext
Loop
If rsPop.RecordCount > 0 Then
SelectButtons True
End If
With lblCount
.Caption = Format((rsPop.RecordCount), "#,##0") & IIf((rsPop.RecordCount) <= 1, " Customer", " Customers") & " found"
.Refresh
End With
rsPop.Close
cnPop.Close
Set rsPop = Nothing
Set cnPop = Nothing
Exit Sub
ErrPopulate:
MsgBox Err.Description, vbCritical, "Populate Error"
End Sub
A listview can have multiple columns, you apparently had at least two columns in your previous listview: Customer Number and Customer Name.
A listbox only has one column. You'll need to decide how to display/add your two columns of data to the listbox. Don't be confused by the columns property of the listbox, when set to multiple columns, the control still only has a single column of data - it simply snakes and scrolls horizontally instead of scrolling vertically.
Adding an item to the listbox:
lv1.Additem rsPop!Customer_Name
Listbox documentation: VB6 Listbox

TListView DynamicAppearance with TImageObjectAppearance will not view image when using LiveBindingsDesigner with TFDMemTable

I am welcoming Embarcaderos efforts to make TListView more dynamically, and was exited to see Sarina Duponts post here where you could just link the imageindex to the TListView properties in LiveBindings Designer, and even the image property to a datafield (integer) when using DynamicAppearance and TImageObjectAppearance.
But... I tried, and did almost succeed.
In my challenge I have an application where I use TFDMemTable with TREST* function to populate the TFDMemTable. All works well if I don't use the DynamicAppearance and use i.e. ImageListItem and links the datafield I want to use to the imageindex property in TListView using LiveBindings Designer.
With DynamicApperance though, there are no imageindex property to link to, but Sarina Dupont says in here post that you could link the integer field directly to the image property (and IDE/compiler will figure it out).
Well... I figured following out: My data fields (semicreated from TREST* and TFDMemTable) are not neccesserely what they seems to be. Since I am using REST/JSON, the fieldtypes are "anonymized" to WideString, actually the FieldDefs->'dataitem'->DataType is set to "ftWideString". I tried to change this value to ftInteger in hope that this would help, but I did just get this errormessage: "FDMemtTable1: Type mismatch in field for 'datafield', exepecting: WideString actual: Integer".
So... I was nearly there, and I really want to use DynamicAppearance and view several images and textfields for each TListViewItem...
...or is it easier to make a ListViewItem 'Template' dynamically and populate it with data instead, and what is the best way to do that ?
I usually try to avoid LiveBindings. The fastest, most stable and easiest way is to add items using code.
ListView1->BeginUpdate();
try {
for (int i = 0; i < arrayOfThings->item.Length; i++) {
TListViewItem* item = ListView1->Items->Add();
item->Text = arrayOfThings->item[i]->item_name;
item->Data["itemName"] = TValue::From<UnicodeString>( arrayOfThings->item[i]->item_name);
item->Data["itemId"] = TValue::From<UnicodeString>( IntToStr( arrayOfThings->item[i]->id ));
item->Data["itemDate"] = TValue::From<UnicodeString>(arrayOfThings->item[i]->item_date);
// adding the image - imgClock is name of the image field [TImageObjectAppearance ] added to items in ItemAppearance in the TListView object that uses DynamicAppereance
const UnicodeString imgClock = L"imgClock";
dynamic_cast<TListItemImage*>(item->Objects->FindDrawable(imgClock))->Bitmap = //bitmap source;
}
} catch (...) {
}
ListView1->EndUpdate();

Transfer a data set from openoffice base to calc

After I did a query in openoffice-base over a customized form I want to transfer a selected set of data into a template openoffice-calc table. I know I can access the data set in openoffice-calc via pressing the Data Source (F4) button but then I only get access over the query. The best solution would be after the database query over a form a button event is required to open a openoffice-calc table from the template and insert the data from the data set.
First go to Tools -> Macros -> Organize Macros -> LibreOffice Basic and add this code. Change the path of the template file.
Sub Copy_Record_To_Calc(oEvent)
Dim oForm
Dim templatePath As String
Dim oServiceManager As Object, oDesktop As Object
Dim oFileProperties As Object
Dim oDoc As Object, oSheet As Object, oCell As Object
Dim column As Integer
oForm = oEvent.Source.getModel().getParent()
If oForm.isAfterLast() Then
Print "Hey, you are after the last element."
Exit Sub
ElseIf oForm.isBeforeFirst() Then
Print "Hey, you are before the first element."
Exit Sub
End If
templatePath = "file:///C:/Users/JimStandard/Desktop/Untitled 2.ots"
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
Set oFileProperties(0) = new com.sun.star.beans.PropertyValue
oFileProperties(0).Name = "AsTemplate"
oFileProperties(0).Value = True
Set oDoc = oDesktop.loadComponentFromURL( _
templatePath, "_blank", 0, Array(oFileProperties))
oSheet = oDoc.Sheets(0)
For column = 1 to 2
oCell = oSheet.getCellByPosition(column - 1, 0)
oCell.String = oForm.getString(column)
Next column
End Sub
Then in form design mode, right-click on the button and choose Control. In the Events tab, click the three dots next to Execute action. Click Macro... and find the Copy_Record_To_Calc macro that you added.
Now turn design mode off. Go to a record and click the button. It will open the Calc template and copy the first two columns of the current record into column A and B of the spreadsheet.
See also:
Section 4.2.1 of Andrew Pitonyak's Base Macros (PDF)
ResultSet documentation
This thread gives an example of using a Calc template.

How may I add additional data for each existing item in a `TListView`?

I'm working with TListView and I have successfully populated each item's caption and first subitem. See example below.
user pass working status valid
data1 pass --- ---
data2 pass2 ---- -----
-
-
-
After populating each item, I acquire additional data for each item. I want to add this data to populate each item's 'working', 'status', and 'valid' columns. How may I add this additional data for each item?
Each time I have tried, it appears the data is being stored in new items and displayed below the original items. See example below.
user pass working status valid
data1 pass --- ---
data2 pass2 ---- -----
yes 2009
no
How may I add additional data for each existing item in a TListView?
How are you updating the existing items?
It should be something like:
ListView1.Items[0].SubItems[1] := 'Yes';
ListView1.Items[0].SubItems[2] := '2009';
ListView1.Items[1].SubItems[1] := 'No';
I'm not sure I understand the question either.
If you want the columns to be visible, you will need to add columns in the object inspector. (I guess you've already done this).
When you are adding listview items, your code will be something like;
MyItem:=ListView1.Items.Add;
MyItem.Caption:='data1';
for i:=0 to 2 do // this is number of desired subcolumns -1
MyItem.SubItems.Add(''); // puts blank string in each cell
// then put your data in;
MyItem.SubItems[0]:='pass';
MyItem.SubItems[1]:='---';
MyItem.SubItems[2]:='--'
//etc

Resources