ComboBox and ToolStripComboBox

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Now,
I know I can often be over-critical of VB, but here is one for the crowd:
I have comboboxes and a single ToolStripComboBox on the form. Everything about these two controls is identical in terms of usage and user interface. There is a SeletedIndex, a text, and an Items() property. I can read when someone is typing or when they select something from the drop down list, and they both have selstart and sellength and selectedtext properties.

But now for the stupid part:
VB.NET:
sub CB_ComboBox(Sender as ComboBox, eClipFunc as MyClipBoardFuncEnum)
  select case eclipfunc
    'operations
  end select
end sub

THis always dies, because for some reason the ToolStripComboBox does not descend from the same base control as ComboBox. So i have to write TWO diferent methods to handle this or do some funky CType() conversion everytime i wish to access the sender.

I have 20 ComboBoxes, and 1 ToolStripComboBox - How can I get VB to access them all in 1 Function, since (duh) they're all COmboBoxes!

Jaeden "Sifo Dyas" al'Raec Ruiner

PS - FOr Posterity, here is the actual function I use to handle my clipboard functionality. I know there is some default functionality but not all controls come with clipboard abilities, and if you overwrite the keyboard once, you have to code for all, plus I am doing many other things in teh background as well, despite the simplicity of this function.

VB.NET:
	Sub CB_ComboBox(sender As ComboBox, eFunc As ClipboardFunctionEnum)
		Select Case eFunc
			Case ClipboardFunctionEnum.Clear: sender.Text = ""
			Case ClipboardFunctionEnum.Copy
				If sender.SelectionLength > 0 Then
					Clipboard.SetText(sender.SelectedText)
				Else: Clipboard.SetText(sender.Text): End If					
			Case ClipboardFunctionEnum.Cut
				CB_ComboBox(sender, ClipboardFunctionEnum.Copy)
				CB_ComboBox(sender, ClipboardFunctionEnum.Clear)
			Case ClipboardFunctionEnum.Paste
				If sender.DropDownStyle = ComboBoxStyle.DropDownList Then Exit Sub
				Dim i As Integer = sender.SelectionStart
				If sender.SelectionLength > 0 Then 
					sender.SelectedText = ClipBoard.GetText
				ElseIf (i >= 0) AndAlso (i <= sender.Text.Length) Then
					sender.Text = sender.Text.Insert(i, Clipboard.GetText)
				End If
				If i > -1 Then sender.SelectionStart = i
			Case ClipboardFunctionEnum.SelectAll: sender.SelectAll
		End Select
	End Sub
 
ToolStripComboBox is not a ComboBox, it is a ToolStripControlHost hosting a ComboBox. Scroll through the class properties in documentation and click into its ComboBox property.
 
Back
Top