473,246 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

Custom ComboBox Problems

Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing into
the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the selected
index is correct, but if i check the value after that it
is set to the previous value. if i select item one, the
value is -1, if i then select item 3 the value is 1. If i
remove the code to drop down the list the value is correct.

It sounds similar to a problem mark was having on Jan 7th,
only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = -1))
Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text field,
a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()
{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange"
, "Pineapple", "Pineberries", "Pinenuts", "Strawberries"})
Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " & Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class
Nov 20 '05 #1
5 2123
Hi,

They showed how to make one in a vbtv episode. Here is a link to
the code.
http://www.gotdotnet.com/Community/U...a-09bc8fd2860b

Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in message
news:60****************************@phx.gbl...
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing into
the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the selected
index is correct, but if i check the value after that it
is set to the previous value. if i select item one, the
value is -1, if i then select item 3 the value is 1. If i
remove the code to drop down the list the value is correct.

It sounds similar to a problem mark was having on Jan 7th,
only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = -1))
Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text field,
a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()
{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange"
, "Pineapple", "Pineberries", "Pinenuts", "Strawberries"})
Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " & Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class

Nov 20 '05 #2
Hi Ken,

if i add the code,

Me.DroppedDown = True

to the keypress event in this component i get the same
undesireable behavior.

ross
-----Original Message-----
Hi,

They showed how to make one in a vbtv episode. Here is a link tothe code.
http://www.gotdotnet.com/Community/U...es/Details.asp x?SampleGuid=30138e02-c2c3-41cd-bc6a-09bc8fd2860b
Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in messagenews:60****************************@phx.gbl...
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing into the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the selected index is correct, but if i check the value after that it
is set to the previous value. if i select item one, the
value is -1, if i then select item 3 the value is 1. If i remove the code to drop down the list the value is correct.
It sounds similar to a problem mark was having on Jan 7th, only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = - 1)) Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text field, a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()
{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange" , "Pineapple", "Pineberries", "Pinenuts", "Strawberries" }) Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " & Me.SelectableComboBox1.SelectedIndex End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class

.

Nov 20 '05 #3
Hi,

untested
http://www.thecodeproject.com/vb/net...e_combobox.asp

Ken
--------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in message
news:5b****************************@phx.gbl...
Hi Ken,

if i add the code,

Me.DroppedDown = True

to the keypress event in this component i get the same
undesireable behavior.

ross
-----Original Message-----
Hi,

They showed how to make one in a vbtv episode.

Here is a link to
the code.
http://www.gotdotnet.com/Community/U...es/Details.asp

x?SampleGuid=30138e02-c2c3-41cd-bc6a-09bc8fd2860b

Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote

in message
news:60****************************@phx.gbl...
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing into the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the selected index is correct, but if i check the value after that it
is set to the previous value. if i select item one, the
value is -1, if i then select item 3 the value is 1. If i remove the code to drop down the list the value is correct.
It sounds similar to a problem mark was having on Jan 7th, only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = - 1)) Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text field, a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()
{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange" , "Pineapple", "Pineberries", "Pinenuts", "Strawberries" }) Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " & Me.SelectableComboBox1.SelectedIndex End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class

.

Nov 20 '05 #4
Not exactly what i was looking for. Half the time
pressing 'A' will get you Apple with the cursor at the end
of the word and half the time it will select 'Apple' with
a selection and the cursor before the 1st 'p' (what i
would expect).

Looks like it is also be providing the previous
selectedIndex when the list drops down which has been my
problem.

thx,

ross
-----Original Message-----
Hi,

untested
http://www.thecodeproject.com/vb/net...plete_combobox ..asp
Ken
--------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in messagenews:5b****************************@phx.gbl...
Hi Ken,

if i add the code,

Me.DroppedDown = True

to the keypress event in this component i get the same
undesireable behavior.

ross
-----Original Message-----
Hi,

They showed how to make one in a vbtv episode.

Here is a link to
the code.
http://www.gotdotnet.com/Community/U...ples/Details.a sp
x?SampleGuid=30138e02-c2c3-41cd-bc6a-09bc8fd2860b

Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote

in message
news:60****************************@phx.gbl.. .
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing

into
the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the

selected
index is correct, but if i check the value after that
it is set to the previous value. if i select item one, the value is -1, if i then select item 3 the value is 1.

If i
remove the code to drop down the list the value is

correct.

It sounds similar to a problem mark was having on Jan

7th,
only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = -
1))
Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text

field,
a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component

list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As

System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer. 'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()

{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange"
, "Pineapple", "Pineberries", "Pinenuts", "Strawberrie s" })
Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender

As System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " &

Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class


.

.

Nov 20 '05 #5
I worked around the initial problem by setting a public
variable in the leave and selectedindexchanged events
which i can access instead of selectedindex.

I am still having the same problem that the leave event is
not firing if the user clicks off the combobox while the
dropdown list is displayed.

Any help would be greatly appreciated!
-----Original Message-----
Hi,

untested
http://www.thecodeproject.com/vb/net...plete_combobox ..asp
Ken
--------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in messagenews:5b****************************@phx.gbl...
Hi Ken,

if i add the code,

Me.DroppedDown = True

to the keypress event in this component i get the same
undesireable behavior.

ross
-----Original Message-----
Hi,

They showed how to make one in a vbtv episode.

Here is a link to
the code.
http://www.gotdotnet.com/Community/U...ples/Details.a sp
x?SampleGuid=30138e02-c2c3-41cd-bc6a-09bc8fd2860b

Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote

in message
news:60****************************@phx.gbl.. .
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing

into
the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the

selected
index is correct, but if i check the value after that
it is set to the previous value. if i select item one, the value is -1, if i then select item 3 the value is 1.

If i
remove the code to drop down the list the value is

correct.

It sounds similar to a problem mark was having on Jan

7th,
only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = -
1))
Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text

field,
a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component

list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As

System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer. 'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()

{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange"
, "Pineapple", "Pineberries", "Pinenuts", "Strawberrie s" })
Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender

As System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " &

Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class


.

.

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jean | last post by:
hi: i am developing a custom combobox for my company's needs that is made up of a textbox, listbox, button. i am using c#. everything is fine except for one issue. in a normal combobox,...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
1
by: Marty Cruise | last post by:
I have a custom collection which contains instances of a custom class. With me so far? OK, now I set the datasource of a combobox to the collection, having overridden the ToString() function of...
2
by: Don | last post by:
I've been trying to create a custom collection that can be bound to a combobox via the DataSource property, but I can't seem to get it to work. I've created a class that implements IList, and it...
3
by: Bob | last post by:
Thinking two things, 1- Creating a userControl -yeah you guessed it, a multi column drop down combobox - I've looked at several articles and did not find what I need, one that's bindable and that...
3
by: Richard Ryerson | last post by:
I have a general DataGridComboBoxColumn that I built using the Example in the .NET 2003 Combined Collection help file (that was a data time picker). I am able to assign a data source and display...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
0
by: Mike | last post by:
Hey everyone... I've got three problems with a custom DataGridView column I've built following the "How To: Host Controls in Windows Forms DataGridView Cells" article. The base editing control...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.