RobertNZana
asked on
How set minimum width of listbox?
How can I set the MINIMUM width of a listbox control, so that when there are NO ITEMS it is 150px, but when there are items in it the listbox gets wider to FIT the longest item, so there's no scrollbar?
Hi,
on the Page_Load event you could check if there are any items in the listbox and if not set the width to 150px. Also i you might be able to loop through the items in the list box and get the length of the logest and work off that. Something like:
Page_Load()
{
if(ListBox.Items.Count = 0)
{
ListBox.Width = 150px;
}
}
HTH
-M3mph15
on the Page_Load event you could check if there are any items in the listbox and if not set the width to 150px. Also i you might be able to loop through the items in the list box and get the length of the logest and work off that. Something like:
Page_Load()
{
if(ListBox.Items.Count = 0)
{
ListBox.Width = 150px;
}
}
HTH
-M3mph15
ASKER
I had that part already. But, let's say it's set to 150px then the user adds an item to the listbox. I cannot set it to 0, or it's too narrow. How can I "NULLIFY" the value once it's set?
Hi,
Why do you want to Nullify the value?
Why do you want to Nullify the value?
ASKER
If a value for the width is set I cannot "remove" the defined width value. Setting it to 0 doesn't work either. I need to put it in a state as if the width was never set, so it will expand dynamically based on the largest listitem width.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I ended up using a checkbox list control, which suited my needs. But I gave u the points... :)
Use the title tag to show a tooltip to the user.
Use the databound event of the listbox
Open in new window