Example of using the ListBox

Jan 7, 2010 at 6:38 PM

I've been having trouble displaying the listbox control even after binding it to a datasource. I figure there must be a trick that I'm not getting. I tried using one of the queries someone had as reference, but I still don't see anything when I run it. Therefore I ask, can someone give me an example of the listbox displaying a simple list such as :one, two, three.

This is what I got from an example, but it still doesn't show me anything.

FluidPanel mainPanel = new FluidPanel(0, 0, Width, 30);

BindingList<object> source = new BindingList<object>();
source.Add("one");
source.Add("two");
source.Add("three");

const int headerHeight = 32;
const int spacing = 3;

FluidListBox flb = new FluidListBox(spacing, headerHeight + spacing * 2, Width - spacing * 2, 30 - headerHeight);
flb.DataSource = source;
flb.BorderColor = Color.LightGray;
flb.SelectedForeColor = Color.Red;
flb.ItemHeight = 32;
flb.Visible = true;
flb.Enabled = true;
Controls.Add(flb);
Jan 9, 2010 at 8:56 AM

Hi UncleGates,

The FluidListBox uses 'Templates' to display the Items. This is what is missing in your code.

The Template is a class derived from FluidTemplate (I am not sure if the name is correct, you might want to crosscheck in the Passwordsafe source, there are some templates defined) which holds e.g. a Label that would be used to display your One,Two,Three. To draw an item the list simply binds the item to template (there is a method your need to override in the Template where you can take of the binding) and then lets the template draw itself at its position. This is done for any item.

This should get you in the right direction.

Hope it helps,

schaze