WebListBox and poor styling functionalities for the selected rows

Hi there,

I’m using a color code for the background of a WebListBox cells to display the status of various processes in a workflow.
I’d like to keep this color code even when the row is selected. I’m aware of the WebListBox.SelectionStyle property.
Depending on the workflow status, there can be different background colors in the same row, and this property works at the row level only. I tried to workaround this by introducing some CSS in the App.HTMLHeader to catch the SelectionStyle CSS selector name, but this name is randomly generated.
As long as we can’t introduce pictures in webListbox, I have to use some unicode symbols to keep the status information available to the user even when the row is selected. But depending on the browser used this can go to barely acceptable look to a definitively ugly interface.
So I’m looking for other ideas to achieve this styling of the selected rows of a WebListBox. Any proposal?

[quote=177602:@Eric de La Rochette]Hi there,

I’m using a color code for the background of a WebListBox cells to display the status of various processes in a workflow.
I’d like to keep this color code even when the row is selected. I’m aware of the WebListBox.SelectionStyle property.
Depending on the workflow status, there can be different background colors in the same row, and this property works at the row level only. I tried to workaround this by introducing some CSS in the App.HTMLHeader to catch the SelectionStyle CSS selector name, but this name is randomly generated.
As long as we can’t introduce pictures in webListbox, I have to use some unicode symbols to keep the status information available to the user even when the row is selected. But depending on the browser used this can go to barely acceptable look to a definitively ugly interface.
So I’m looking for other ideas to achieve this styling of the selected rows of a WebListBox. Any proposal?[/quote]

You could finely manage the background and selection colors directly at the cell level with JavaScript.

If you take a look at WebCustomUI: http://37.187.7.210/cgi-bin/webcustomui/webcustomui.cgi

You will see that the Selection color of a Row can be changed with CSS.
In order to achieve this, you need to setup the CSS for the listbox using a WebPageSource control.
In the Shown event of the PageSource control, the ControlID of the WebListbox is already defined.

You can this way :

  • Place a token in the text of your WebListBox. For instance, in a cell, place “MyImage” as text
  • Use this code to show the picture :

ListBox1.ExecuteJavaScript("var toReplace = 'MyImage'; var replaceWith =""<img style='width: 102px; height: 40px;' src='http://www.fontmenu.com/pics/fontmenubutton.gif'>""; document.body.innerHTML = document.body.innerHTML.replace(toReplace, replaceWith);")

I have used a picture from my web site, but you can also use a webfile pointing to the picture and use webfile.urlpath.

[quote=177625:@Michel Bujardet]You can this way :

  • Place a token in the text of your WebListBox. For instance, in a cell, place “MyImage” as text
  • Use this code to show the picture :
    […][/quote]
    Nicely done! I’ll give it a try. Thank you.

I’ve already seen your tremendous work and I think that at one point in the future I might have to give it a deeper look.

Thank you Michel!

What I did not mention is that you can mix icons and text, with a token like
MyIcon This is a text
You can also put all sorts of HTML to change text color in the cell, attributes, text size…

As I’m running out of time, I’ve used a few icons stored in a folder of the Apache server and the App.HTMLHeader property to enhance already defined WebStyles in order to add a ‘background-image’ property to the WebList cells. It works fine and fast, but the icons links are harcoded with an absolute URL in a HTML tag in the page header. It’ll do it for the upcoming test period. But as soon as I’m back, I’ll have a better look into Michel’s hack. :slight_smile:

Here is the result:

Thank you Michel !!!

It appears once javascript replaces the token text with some HTML the listbox looks great but becomes unresponsive to mouse events. I can use the scroll wheel but dragging the scroll bar or mouse down events don’t work.

You are right. Even the most simple text replace gets the control stuck :frowning:

I have repeatedly tested this with replacing every token or just the first. It simply locks the listbox and no method, event or anything works. Unless you embed it with a container so you can destroy it and do not need to interact with it - dont use this method.

The problem is that when you muck with the DOM manually like this, the events were connected to the one you replaced. This does not surprise me at all.

People like myself with limited experience to JS and Xojo often read .executejavascript as “I can do anything I want, what harm could it possibly do”.

The LR really should be updated to help others experimenting with these types of issues to warn them of the pitfalls.

Nothing in computing comes without some amount of karma. People who use WE regularly do use JS a lot to work around the many limitations of Xojo, but it does not always work.

To be honest, the WebSDK is here to create custom controls. That said, I am not too sure creating a custom WebListBox that support changing cells colors is any easier than using an HTML table in a Page Source (which I find better than the HTMLViewer as tapping into an iFrame is yet another pile of joy).

Maybe the best route would be to purchase a third party control and be done with it. I never used it, but Jrmie Leroy’s UI Listbox is impressive http://jeremieleroy.com/products/customui.php?PHPSESSID=bb6f3cb37218da9ca151374aae92ffff

Along those lines…WebListBoxTD in Web Custom Controls supports HTML in cells. The demo on my site let’s you use CLEditor (another control in the kit) to add rows and set cells in a sample list box.

In light of Greg’s comment, this particular control is not a unique control running on an SDK (mine in 1.3.3; the official one in the coming 2.0 release). I’ve subclassed WebListBox and “mucked around” with it a bit. The pro is that you can literally change the Super of a WebListBox already on your page and call the new methods to set cell HTML. Your other existing WebListBox code should work fine. The con is that I can’t guarantee future Xojo releases won’t break this control requiring an update from me.

This has been a popular control and, FWIW, it has held up well so far.

[quote=180061:@Daniel Taylor]Along those lines…WebListBoxTD in Web Custom Controls supports HTML in cells. The demo on my site let’s you use CLEditor (another control in the kit) to add rows and set cells in a sample list box.

In light of Greg’s comment, this particular control is not a unique control running on an SDK (mine in 1.3.3; the official one in the coming 2.0 release). I’ve subclassed WebListBox and “mucked around” with it a bit. The pro is that you can literally change the Super of a WebListBox already on your page and call the new methods to set cell HTML. Your other existing WebListBox code should work fine. The con is that I can’t guarantee future Xojo releases won’t break this control requiring an update from me.

This has been a popular control and, FWIW, it has held up well so far.[/quote]

Looks very good :slight_smile:

Well Daniel, I just purchased. Lets see what your custom controls can do…

For anyone looking to remove the “transparency and white text” default styling of the selected rows I have a helper method to do this. This allows your manually assigned cell background color and text color to show through and it completely removes the appearance that rows have been selected.

ListBox1.UseDefaultSelectionStyle = false[/code]

Add this method to a module to use:
[code]Sub UseDefaultSelectionStyle(extends lb as WebListBox, assigns allow as Boolean)
  dim styleId as string = lb.ControlID+"_NoDefaultSelectionStyle"
  if allow then
    dim s as string = "<style type='text/css' id='"+styleid+"'>" + _
    "div.listbox #<<control_id>>_content tr.selected td" + _
    "{" + _
    "    background-color: transparent !important;" + _
    "    color: inherit !important;" + _
    "}" + _
    "</style>"
    lb.ExecuteJavaScript(lb.JqeurySelector+".append("""+s.Replace("<<control_id>>",lb.ControlID)+""");")
  else
    lb.ExecuteJavaScript("$('#"+styleId+"').remove();")
  end
End Sub

This also uses JQuery to implement so you will to add this to the App.HTMLHeader property as well

<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script>