newyuppie
asked on
combobox text longer than combobox width
vb 2005
is there any way to have a dropdown combobox which has very long text items to show the full text when mouse is over the item?
thanks
is there any way to have a dropdown combobox which has very long text items to show the full text when mouse is over the item?
thanks
ASKER
eric,
using your philosophy, how could i check if the length of the text is longer than the width of the combobox to set the tooltip?
(independent of the font used and stuff. i mean, i could have different comboboxes with different font styles and sizes, how could i compare the widths of text and control?)
thanks
using your philosophy, how could i check if the length of the text is longer than the width of the combobox to set the tooltip?
(independent of the font used and stuff. i mean, i could have different comboboxes with different font styles and sizes, how could i compare the widths of text and control?)
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok we are onto something here.
my problem with that code is that i have to actually select one of the items to have the tooltip displayed. but what if the items are not completely shown because the combobox is too small, i need to display the tooltip when i hover each item, without necesarily having to click one of them. how would i capture that?
my problem with that code is that i have to actually select one of the items to have the tooltip displayed. but what if the items are not completely shown because the combobox is too small, i need to display the tooltip when i hover each item, without necesarily having to click one of them. how would i capture that?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ended up using combination of your code and the code on the link.
thank you!
had to adapt the code because my combobox is data bound, and had to use DataRowView for the items loop
** code
Private Sub ComboBox_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox.DropDown
Dim senderCBO As ComboBox = Nothing
senderCBO = CType(sender, ComboBox)
Dim g As Graphics = senderCBO.CreateGraphics()
Dim mFont As Font = senderCBO.Font
Dim width As Integer = senderCBO.Width
Dim vertScrollBarWidth As Integer = (senderCBO.Items.Count > senderCBO.MaxDropDownItems ) * SystemInformation.Vertical ScrollBarW idth
Dim newWidth As Integer
For Each drv As DataRowView In senderCBO.Items
newWidth = CType(g.MeasureString(drv( "category" ).ToString , mFont).Width, Integer) + vertScrollBarWidth
If width < newWidth Then
width = newWidth
End If
Next
senderCBO.DropDownWidth = width
End Sub
Private Sub ComboBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles ComboBox.MouseMove
Dim senderCBO As ComboBox = Nothing
senderCBO = CType(sender, ComboBox)
Dim g As Graphics = senderCBO.CreateGraphics()
Dim mFont As Font = senderCBO.Font
If Fix(g.MeasureString(sender CBO.Text, mFont).Width) > senderCBO.Width Then
Me.ToolTip1.SetToolTip(sen derCBO, senderCBO.Text)
Else
Me.ToolTip1.SetToolTip(sen derCBO, String.Empty)
End If
End Sub
thank you!
had to adapt the code because my combobox is data bound, and had to use DataRowView for the items loop
** code
Private Sub ComboBox_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox.DropDown
Dim senderCBO As ComboBox = Nothing
senderCBO = CType(sender, ComboBox)
Dim g As Graphics = senderCBO.CreateGraphics()
Dim mFont As Font = senderCBO.Font
Dim width As Integer = senderCBO.Width
Dim vertScrollBarWidth As Integer = (senderCBO.Items.Count > senderCBO.MaxDropDownItems
Dim newWidth As Integer
For Each drv As DataRowView In senderCBO.Items
newWidth = CType(g.MeasureString(drv(
If width < newWidth Then
width = newWidth
End If
Next
senderCBO.DropDownWidth = width
End Sub
Private Sub ComboBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
Dim senderCBO As ComboBox = Nothing
senderCBO = CType(sender, ComboBox)
Dim g As Graphics = senderCBO.CreateGraphics()
Dim mFont As Font = senderCBO.Font
If Fix(g.MeasureString(sender
Me.ToolTip1.SetToolTip(sen
Else
Me.ToolTip1.SetToolTip(sen
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ComboBox1.Items.Add("1.
Me.ComboBox1.Items.Add("2.
Me.ComboBox1.Items.Add("3.
End Sub
Private Sub ComboBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
If Me.ComboBox1.Text.Length > 0 Then
Me.ToolTip1.SetToolTip(Me.
Else
Me.ToolTip1.SetToolTip(Me.
End If
End Sub