Hello, there was a problem with working with ListBox 'mi.

The program provides two ListBox 'a, four buttons. The first two buttons drag one line from one list to another (1-> 2 and 2-> 1, respectively). The second two buttons drag the selected group in the same way as the first two buttons. The problem is as follows:

  1. How to make the program check whether we have selected any item in the list or not? If not selected, the button for this list simply does not work.

  2. In general, how to set up checks in order for us to select a line in the list, without using the ListBox Clik procedure, so that everything works exclusively through buttons?

  • one
    ListBox1.SelCount - the number of selected entries. The verification condition should be based on it. - KiTE

1 answer 1

ListBox1.ItemIndex returns the index of the selected row and -1 , if no rows are selected, for a single selection.

For multiple selection ( MultiSelect = true ), you can check whether a particular row is selected using the Selected[Index: integer] property. For selected lines, this value will be true .

For example, you can identify all selected lines:

  for i := 0 to ListBox1.Count - 1 do if ListBox1.Selected[i] then begin // делаем что-то с выделенной строкой end; 

And, of course, as @KiTE said, SelCount will show the number of selected lines.

  • But is it possible about a single selection in more detail? That is, we must first set ListBox1.SelCount = 1 then what are we going to do? - tkoff
  • one
    Yes you can. If we want to distinguish exactly a single selection from a plural one. - Nofate