This is a migrated thread and some comments may be shown as answers.

DropDownWidth and Tooltip

3 Answers 180 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
david
Top achievements
Rank 1
david asked on 24 Jul 2008, 04:20 PM
How can I automatically resize the dropdown part to be wide enough to hold the longest item?

How can I make the tooltip when the list is dropped down show the item under the mouse?

Thanks

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 28 Jul 2008, 08:49 AM
Hello david,

  РadComboBox does not have the functionality to change the width of dropdown window according to the items in it. However, there is a solution, which uses DropDownOpened event (available only in our latest version - Q2 2008). In the event handler you could calculate the width, which then will be set to the popup form. Here is the code:

    private void radComboBox1_DropDownOpened(object sender, EventArgs e)  
    {     
        //getting the popup form which size should be set  
        RadPopupForm popup = (RadPopupForm)radComboBox1.Items[0].ElementTree.Control;  
 
        int desiredWidth = (int)radComboBox1.ComboBoxElement.ListBoxElement.Viewport.DesiredSize.Width;  
        RadScrollLayoutPanel scrollPanel = (RadScrollLayoutPanel)radComboBox1.ComboBoxElement.ListBoxElement.Children[2];  
 
        if (scrollPanel.CanVerticalScroll)  
        {  
            desiredWidth += radComboBox1.ComboBoxElement.ListBoxElement.ScrollThickness;  
        }  
 
        //adding border width (both left and right) of the inner listbox element.   
        desiredWidth += radComboBox1.ComboBoxElement.ListBoxElement.BorderThickness.Horizontal;  
 
        popup.Size = new Size(desiredWidth, popup.Height);  
    } 

First, the desired width is obtained, which would be the width of the longest item. Then we check using the scroll panel object whether the vertical scroll bar is visible. If it is, we add its width too. In addition we add the width of the both left and right border. Finally the new size is assigned.

As to the tooltips, you should merely put the necessary text in the item's ToolTipText property and it will appear on mouse hovering.

I hope this helps! If you have additional questions, please write us again.

Kind regards,
Georgi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
david
Top achievements
Rank 1
answered on 28 Jul 2008, 07:57 PM
Hi Georgi,

This workaround had occurred to me, but I was looking to the Telerik control to provide some functionality above and beyond what the microsoft control is able to do. I see no point in using a 3rd party control and then just doing the same workaround that I need to do to use the generic control. That is what I have ended up with - I am using the MS control and doing a measurestring in the dropdownopened event.

For the second point. I don't think it is as easy as you suggest. You say "you should merely put the necessary text in the item's ToolTipText property". What pray tell is the necessary text? the text that one would want is the display value of the item currently under the mouse in the list... where is this text exposed by the api? What is the event that fires when the mouse changes to a new item?

I know that is can be achieved by hooking the mouse move event, calculating which item is at the mouse X Y pos, then looking up the text from the datasource and putting it in the tooltip but *sigh* why am _I_ dong all the work? What would you say are the advantages of using the Telerik controls over the default microsoft ones? Okay themeing, but I am writing a business application where the controls are SUPPOSED to look like generic windows controls. I would have thought it was small, fairly simple to implement (internally) features like these two that would make the Telerik control the OBVIOUS choise over the generic.

Thanks!
0
Georgi
Telerik team
answered on 31 Jul 2008, 07:15 AM
Hello David,

Thank you for your suggestions. Initially we designed RadComboBox to have at least the same features as the standard MS combobox. The additional features which our control have are well described in our documentation topics. As the time goes by we're extending the functionality of RadComboBox and we'll consider adding the features you suggested in the future.

As to the tooltips, in case of dynamically assigning tooltip text, the solution is a bit more tricky. Actually there is an already existing event which is intended exactly for the same purpose - RadControl.ToolTipTextNeeded (described in this topic in our documentation). In the event handler you will set the necessary text to the ToolTipTextNeededEventArgs.ToolTipText property. The tricky moment in this approach is obtaining the instance of RadControl which in this case is the popup form of the combobox. To get this instance you should use something like this:

RadPopupForm popup = (RadPopupForm)radComboBox1.ComboBoxElement.ListBoxElement.ElementTree.Control;  
popup.ToolTipTextNeeded += new ToolTipTextNeededEventHandler(popup_ToolTipTextNeeded);  
 
 

Another solution could be to use RadComboBoxItemDataBound event (described in this topic in our documentation). In the event handler you could set directly the tooltip text to the ToolTipText property of the ItemDataBoundEventArgs.DataBoundItem which represents the RadComboBoxItem displayed in the drop-down window.

I hope this information would help. If you have any additional questions, please don't hesitate to write us again.

Best wishes,
Georgi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
david
Top achievements
Rank 1
Answers by
Georgi
Telerik team
david
Top achievements
Rank 1
Share this question
or