0

I'm currently displaying "merchandise" in a ListView, the listview has article, quantity, iemsls and name.

On DoubleClick of the item I want to read the variables and put them in TEdit field, and 'iemsls' in a ComboEdit which has items pre-written, how can I check which item from the ComboEdit equals the same as of the String and set it to that?

      igiDoubleTap:
     begin
     global_norakstisanadoc_editing := true;
     SelectedItemIndex := F_SS_MAIN.ListView2.Selected.index;

     ListView2.Enabled := false;
     SpeedButton6.Enabled := false;
     SpeedButton7.Enabled := false;

     quant_bef := (TListItemText(F_SS_MAIN.ListView1.Items.AppearanceItem[index].Objects.FindDrawable('Text2')).Text);
     quant_aft := StringReplace(quant_bef, 'gb', '', [rfReplaceAll, rfIgnoreCase]);

     Edit_artikuls_norakstisana.Text := ListView2.Items.Item[SelectedItemIndex].View.FindObject('artikuls').Data.ToString;
     edit_daudzums_norakstisana.Text := quant_aft;
     label_prece_from_ean.Text := ListView2.Items.Item[SelectedItemIndex].View.FindObject('prece').Data.ToString;

     ComboEdit := ListView2.Items.Item[SelectedItemIndex].View.FindObject('iemsls').Data.ToString;

     end;

This is currently the DoubleTap method I'm using

5
  • 2
    1. Read the string which you want to search for. 2. Iterate over each item in the combo. 3. Compare the search string against each item in the combo yielded by step 2. Commented Feb 11, 2019 at 11:31
  • @DavidHeffernan Is there a way of exiting a for loop? I'm currently going into a loop from 0 to ComboEdit1.items.count, and doing an if ComboEdit1.items[ComboEdit1.ItemIndex[i]] = 'the string', how can i exit the loop when the string is found? Commented Feb 11, 2019 at 11:40
  • 1
    Read the documentation: docwiki.embarcadero.com/RADStudio/en/… Commented Feb 11, 2019 at 11:41
  • 1
    Take a look at 1. the Delphi Language Guide. Read if from begin(ning) to end. 2. Then concentrate on the command Break. Commented Feb 11, 2019 at 11:42
  • 1
    a for loop is an unconditional loop, it will run until it reached the ends of its index. If you want your loop to stop on a condition, use a conditional loop, such as while do or repeat until There are ways to break from a for loop, but IMO you have used the wrong loop when you need that Commented Feb 11, 2019 at 14:22

1 Answer 1

1

In both VCL and FMX, The TComboBox.Items property is a TStrings object that has an IndexOf() method, and TComboBox has an ItemIndex property for setting the currently selected item by index.

So, try this:

ComboEdit1.ItemIndex := ComboEdit1.Items.IndexOf(
  ListView2.Items.Item[SelectedItemIndex].View.FindObject('iemsls').Data.ToString
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.