Arjan van Dijk submitted to the Omnis Underground list:
I want to use icons in a dropdown list. I use the style(kescbmp,<iconid>) command in my dropdown calculation to accomplish this.
This works fine. The icons appears in the list. But, when you select an item from the list, the icon will disappear and is replaced by the escape codes.
I don't want to use the icon droplist because it is very sloppy.
Here is my solution in reply:
My guess is that my first article on the style() function got you into this mess. Let’s see if I can get you back out.
As I mentioned in that article (yes, there’s a second one coming this week), only the droplist portion of a Droplist or Combobox field supports styled text. My quick solution for Droplists was to make the first column the one that is displayed in the “field” part of the field (by making the width of the field too narrow to display additional columns), but this is not a very elegant solution. In fact, it just won’t work for your great idea to use icons in the droplist because those have to come first.
The trick is in the calculation property. We need to make display of the icon “conditional” and only display it for those lines that are not selected. Our list must contain at least 3 columns then: name (the string to be displayed), iconID and selected. (I have chosen to create that third column rather than rely on the $selected property because I have more control over it.) We could then have a calculation value for the field that reads like this:
The third parameter of the mid() function only needs to be 11, but I like to add a little “slop” when doing this...just in case...
Now we have to make sure the proper line is marked as “selected” and all other lines are not when we click on a line in the droplist. Here is the $event method:
Calculate clickedLine as pRow().$line
Calculate iconList.$line as clickedLine
Calculate iconList.selected as kTrue
We can’t use pLinenumber with a Droplist field evClick event because Omnis Studio doesn’t give us a value for that. It gives us pRow instead. Unfortunately, the value of pRow varies if we try to use it inside of that $sendall() method, so it always points to the last line in the list after that method has completed its job. For this reason, we need a local variable (which I named clickedLine) to keep track of, and eventually reset, the current line of our list variable. Once we have reset all lines to not “selected”, we can set the line the user just clicked on as “selected”.
The result is that our display value no longer contains the escape sequence. A side effect is that this line does not display an icon if the list is dropped, but that is easier to explain away than an ugly group of mystery characters appearing in the display.
You will have to work out for yourself the method for making the proper line in the list variable “selected” as you browse through records with Find, Next and Previous...but I have no doubt you will be able to do that.